Discussion Locked

Scripting Question

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm tring to figureout a way to automaticaly delete old files. Files that are X number of days old. Any thoughts?

8 replies

by nitemare

Hi,

I haven't seen a way to do this the way you mean, but you could:

1. Create a folder to store the data you want to delete.

2. Write a script to move the data to the folder.

3. Schedule a task in Scheduled Tasks/AT to delete all the contents of the folder every X days.

Regards,

by mark

This is easily done in a batch file, but you don't want to arbitrarily delete all files on your HD based on date. You could do this in your document or temp folder, but I fail to see why you have a need for this. Perhaps you should tell us about your problem instead of asking how to implement your solution. I'll take time to give you a batch file to do this once I hear a good reason.

by rjackson

We have an FTP site that our customers use to load stuff to us. I need a way to cleanup this site. My thought was I could write a script that deletes files that are say 30 days old.

by sritter

This is easily done with a vb script.
Here is some sample code.
Set wshShell = WScript.CreateObject("WScript.Shell")
Set fsObj = CreateObject("Scripting.FileSystemObject")

' Location of Folder that contains files
thisDir = "D:\test"

' Findall files in the directory
Set f = fsObj.GetFolder(thisDir)
Set fc = f.Files
For Each fl in fc
' If a file is older than 13 days kill it.
If (Now - fl.DateCreated) > 13 Then
fsObj.DeleteFile fl.name
End If
Next

by rjackson

Thanks this seems to do the trick. The only negitive I can see is that you have to be in the directory that has the files you want to delete for it to run.

This discussion is closed to new replies.