| |||||||
| Windows XP Discuss the Microsoft Windows XP Operating System |
![]() |
| | LinkBack | Thread Tools |
| |||
| Date Based File Purge 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. |
| |||
| Re: Date Based File Purge "Stingray" <Stingray@discussions.microsoft.com> wrote in message news:C34BADBB-AE98-4B21-B228-CE103B93B8C8@microsoft.com... > 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. |
| |||
| Re: Date Based File Purge 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. |
| |||
| Re: Date Based File Purge 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. |
| |||
| Re: Date Based File Purge 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 |
| |||
| Re: Date Based File Purge 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 |
![]() |
| Bookmarks |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Apple and HP readying LED-based notebooks? | LPH | Tablet PC Bloggers | 0 | 01-03-2007 04:10 PM |
| Windows Mail: Delete/Purge works differently in IMAP | Craig L | Windows Vista | 10 | 01-02-2007 10:26 AM |
| Membership Purge | Forum Rearrangements | New Skin | LPH | Announcements | 0 | 10-31-2004 02:42 PM |
| Pen-Based Typing for Tablet PC - AlphaTap! | AlphaTap News | Windows XP Tablet PC Newsgroup | 4 | 05-26-2004 09:10 PM |
| Tablet PCs based on the Dothan Chips | LPH | Tablet PC - In The News | 4 | 05-15-2004 11:35 AM |