?
Solved

file management software

Posted on 2009-04-21
9
Medium Priority
?
246 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:robinyanwang
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:samiam41
ID: 24200298
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).

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23021560.html
0
 
LVL 9

Expert Comment

by:samiam41
ID: 24200323
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
0
 
LVL 8

Accepted Solution

by:
Wikkard earned 1400 total points
ID: 24200338
Try this:
'************************************************************************
'*
'*	This script will loop over all files in the specified folder 
'*	and will delete any old than the specified age
'*	Care must be taken with this script as it will delete files 
'*	without prompts. 
'*
'*	Usage: 
'*	DeleteFiles.vbs [path] [age] [/R] 
'*	[Path] Specifies the path to process
'*	[Age] Specified the age of files in day which will be deleted
'*
'*	/R	Deletes files recursively. All Files under the specified folder older than specified age will be deleted. 
'*
'* 	WARNING: THIS WILL DELETE FILES WITHOUT ANY PROMPTS. DO NOT RUN THIS ON CRITICAL SYSTEM FOLDERS
'*	Example: cscript DeleteFiles.vbs d:\logfiles 31 /R
'*
'*	Created by: Phillip Denley 11/06/08
'************************************************************************
 
 
 
 
dim filecnt 
dim age
dim recursive
dim path 
filecnt = 0 
if WScript.Arguments.Count <2 then 
	WScript.Echo "Usage: "
	WScript.Echo "DeleteFiles.vbs [Path] [Age] [/R]" & vbcrlf 
	Wscript.Echo "[Path] Specifies the path to process"
	Wscript.Echo "[Age] Specified the age of files in day which will be deleted" & vbcrlf 
	wScript.Echo "/R	Deletes files recursively. All Files under the specified folder older than specified age will be deleted. " & vbcrlf 
	Wscript.Echo "Example: cscript DeleteFiles.vbs d:\logfiles 31 /R" & vbcrlf 
	wscript.Echo "WARNING: THIS WILL DELETE FILES WITHOUT ANY PROMPTS. DO NOT RUN THIS ON CRITICAL SYSTEM FOLDERS"
	wscript.Echo ""
	wscript.quit(0)
else 
 
	if NOT isNumeric(wscript.arguments(1)) then 
		wScript.Echo "Age parameter must be numeric"
		wscript.quit(0)
	else 
		path = wscript.arguments(0)
		'validate path parameter ? 
		age = cint(wscript.arguments(1))
		if wscript.arguments.count = 3 then 
			if lcase(wscript.arguments(2)) = "/r" then 
				recursive = "/r"
				wscript.echo "Recursive Mode"
			end if 
		end if 
		recursefiles path
	end if 
end if 
 
 
wscript.echo filecnt  & " files were processed."
 
 
Sub RecurseFiles(Path)
	Const FOR_READING = 1
	strFolder = path
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(strFolder)
	wscript.echo objFolder.Path
	Set colFiles = objFolder.Files
	For Each objFile In colFiles
		ProcessFile (objFile)
	Next
	if recursive= "/r" then 
		ShowSubFolders (objFolder)
	end if 
End Sub
 
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 
	on error goto 0 
end if 
End Sub
 
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)
  Next
End Sub

Open in new window

0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 9

Expert Comment

by:samiam41
ID: 24200361
Test and enjoy.  Should do what you are looking for easier then my previous posts.  For proper disclosure, I found it on EE.  

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23140386.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

0
 

Author Comment

by:robinyanwang
ID: 24200401
should I save it to a bat file?
0
 
LVL 8

Expert Comment

by:Wikkard
ID: 24200434
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.
0
 
LVL 8

Expert Comment

by:Wikkard
ID: 24200439
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.  

0
 

Author Comment

by:robinyanwang
ID: 24206767
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.
0
 
LVL 8

Expert Comment

by:Wikkard
ID: 24210598
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question