Link to home
Start Free TrialLog in
Avatar of robinyanwang
robinyanwang

asked on

file management software

Hi,

I have a temp location for user to store/transfer files on the server, it is a shared public folder.
it says user should delete anything 50 days old, but they never do that, so this folder is getting bigger and bigger.

I am wondering if you guys have been using some file management software to purge into this folder for these files/folders never been modified in past 50 days.
or is there any code/script i can do by myself, and run on the windows 2003 server as a task?

thanks.

Robin
Avatar of samiam41
samiam41
Flag of United States of America image

It looks like there was a similar question asked and received a pretty high score.  Try out the suggestion and script (take note of the experts follow-up post about line 20).

https://www.experts-exchange.com/questions/23021560/Script-to-move-and-delete-files-based-on-age-created-date.html
I also found a really interesting post (if you are a scripter).

http://www.computing.net/answers/programming/batch-file-deleting-files-by-date/13717.html
ASKER CERTIFIED SOLUTION
Avatar of Wikkard
Wikkard
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Test and enjoy.  Should do what you are looking for easier then my previous posts.  For proper disclosure, I found it on EE.  

https://www.experts-exchange.com/questions/23140386/Script-to-delete-files.html?sfQueryTermInfo=1+10+date+delet+file
'
' Script to delete all files in a folder beyond a certain date
'
Dim deletionDate
Dim fso
Dim oFile
Dim oFolder
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("c:\temp")
 
deletionDate = "2007-06-10" 'yyyy-mm-dd
 
 
For Each oFile in oFolder.Files
    If DateDiff("d", oFile.DateCreated, deletionDate) > 0 Then
        ' File exceeds the date selected, delete it
        fso.DeleteFile oFile, True ' Delete it even if it is read only!
    End If
Next
 
Set oFolder = Nothing
Set oFile = Nothing
Set fso = Nothing

Open in new window

Avatar of robinyanwang
robinyanwang

ASKER

should I save it to a bat file?
No These scripts should be saved as .vbs
You run them using cscript.exe
ie. cscript DeleteFiles.vbs d:\logfiles 31 /R
This will delete all files in the d:\logfiles folder (and all subfolders) older than 31 days.

The scipt I posted above even has command line help and can process folders recursively.
If you want to automate this task I would add the above command to a batch file and then schedule it using the task scheduler in windows.  

samiam41, the code you post is good for deleting files under main folder, not in subfolder.

Wikkard,  the code you post can delete files in all sub folder level based on the last modified date.
do you know
1) it can not delete read-only file, how can we modify that?
2) I would like a folder to be deleted if no file/folder under it, is it possiable?

thanks.
I didn't notice that read only files were not deleted.  
Here are a couple of modifications to force deletion of readonly files and to remove the empty folders.

Change the processFile routine as follows:

Sub ProcessFile(file)
FileAge = DateDiff("d",file.DateLastModified, now )
if FileAge  > Age then
      on error resume next
      filecnt = filecnt + 1
      wscript.echo "deleting " & file.Path & " " & file.datelastmodified
      file.delete true 'true will force the deletion
      on error goto 0
end if
End Sub


You can also modify the showSubFolders routine as shown:

Sub ShowSubFolders(objFolder)
  Set colFolders = objFolder.SubFolders
  For Each objSubFolder In colFolders
    wscript.echo objSubFolder.Path
    Set colFiles = objSubFolder.Files
    For Each objFile In colFiles
      ProcessFile (objFile)
    Next
    ShowSubFolders (objSubFolder)
  If objSubFolder.Files.Count = 0 And objSubFolder.SubFolders.Count = 0 Then
    'the level above this is empty
      on error resume next
      wscript.echo "deleting " & objSubFolder
        objSubFolder.Delete true
      on error goto 0
    End If
  Next
End Sub