Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I remove archived files

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
Does anyone have a batch script that I can run daily to remove files that do NOT have the archive bit set ?
 
It is for a specific folder and a specific group of files
eg: del C:/data/archive/ARCH* where archive = " "
 
Open Notepad
Copy the Code below into notepad
Save the file as archive.vbs (or any other name, so long as it ends in .vbs)

Code:
Dim FSO, readfile
Set FSO = CreateObject("Scripting.FileSystemObject")
DoDir FSO.GetFolder(".")
Sub DoDir(Folder)
   On Error Resume Next
   Dim File, SubFolder
   For Each File In Folder.Files
      	set readfile = fso.GetFile(File)
	If NOT readfile.Attributes And 32 Then 
	readfile.delete
	End If
   Next
   For Each SubFolder in Folder.SubFolders
      DoDir SubFolder
   Next
End Sub

Place this file in your required folder and double click it.
This will delete all files in the directory that do not have the archive attribute set, it will also look in sub folders.

If you do not want it to look in sub folders then remove the following code.

Code:
   For Each SubFolder in Folder.SubFolders
      DoDir SubFolder
   Next

Hope this helps, if not let me know

Greg Palmer
Free Software for Adminstrators
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top