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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove files based on file size

Status
Not open for further replies.

MarcusWendel

Technical User
Feb 22, 2002
41
SE
I need to remove the files with a zero filesize in certain folders on one of our servers and to have this job scheduled.
Can this be done with regular DOS commands or do I need to install some small tool?
Thanks.

/Marcus
 
Your best way to do this is with vbscript.

Here is a sample that will do it for you.

Code:
Path1 = "E:\Directory1"

Dim fso 
Dim oFolder
Dim oFile

Set fso = createobject("Scripting.FileSystemObject")
  
Set oFolder = fso.GetFolder(Path1)
  
For Each oFile In oFolder.files
	If oFile.Size = 0 Then
    	oFile.Delete True
    End If
Next

Set oFolder = Nothing
Set fso = Nothing

I hope you find this post helpful.

Regards,

Mark
 
Thanks Mark. I've never used vbscript so this is a very "basic" question: what do I need to do to run that script?

/Marcus
 
Just copy the contents to notepad and save the file as a vbs file instead of txt.

As long as you have IE 6 you will already have the Windows Script Host 5.6 engine installed and it will run when double clicked.

I hope you find this post helpful.

Regards,

Mark
 
Thanks again Mark, I've done some testing and your script seems to have solved my problem.

/Marcus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top