Date Based File Purge

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for a solution to a problem I've been wrestling with for a
couple years and so far I've hid dead ends. I have a low-end NAS device that
we use for storage of our security camera files and have a need to
periodically remove files older than a given date. The big problem is, since
it's a Unix based OS rather than Windows Storage Server based, we cannot
connect to it directly with our backup server, which would be able to do a
simple archive backup and purge the backed up files for us.

I've been searching through utility packages and scripting sites and have
not found anywhere how I could automate the process of searching a directory
tree on a mapped drive and delete any files older than a specified date. Does
anyone out there have any ideas? I'd prefer something that's already written
but I'm not totally opposed to some coding as long as it doesn't get to
advanced. I appreciate any advice or suggestions.
 
Stingray said:
I am looking for a solution to a problem I've been wrestling with for a
couple years and so far I've hid dead ends. I have a low-end NAS device that
we use for storage of our security camera files and have a need to
periodically remove files older than a given date. The big problem is, since
it's a Unix based OS rather than Windows Storage Server based, we cannot
connect to it directly with our backup server, which would be able to do a
simple archive backup and purge the backed up files for us.

I've been searching through utility packages and scripting sites and have
not found anywhere how I could automate the process of searching a directory
tree on a mapped drive and delete any files older than a specified date. Does
anyone out there have any ideas? I'd prefer something that's already written
but I'm not totally opposed to some coding as long as it doesn't get to
advanced. I appreciate any advice or suggestions.

Both xxcopy.exe and robocopy.exe have switches that let
you delete files selectively. xxcopy is downloadable from a
number of sites and robocopy comes with the Windows
Resource Kit.
 
Dim fso, f, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c::\test")
Set fc = f.Files
For Each f1 in fc
If DateDiff("d", f1.DateLastModified, Now) > 15 Then
f1.Delete
End If
Next
Set fso = Nothing
Set f = Nothing
Set fc = Nothing


This VB script was posted in another forum that should help you. I am
checking with a friend to see if he can modify the script so I can also
specify a file type as well. When I get that one back I will post it
too.
 
I have done some basic testing on revised script on the code provided
earlier. This VB code will allow you to specify the folder, file
extension, and date.

FYI you will need to save the file as a VBS and the run it from the
command like this:

wscript filename.vbs
or like
cscript filename.vbs


Dim fso, f, f1, fc
Dim temp, pos
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c:\test") 'Gets the folder
Set fc = f.Files 'gets all of the files in the folder, makes a
collection
For Each f1 in fc 'increments through each of the files in fc
temp = f1.name 'get file name
temp=right(temp,4) 'get the last 4 characters in the string (match
this to the number of characters in the if statement (.txt = 4)
if(temp = ".txt" AND DateDiff("d", f1.DateLastModified, Now) >
15) then 'only delete if it is the correct file type and so old
f1.delete
end if
Next
Set fso = Nothing
Set f = Nothing
Set fc = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top