Solved

Script to List 0kb files

Posted on 2013-01-30
4
600 Views
Last Modified: 2013-02-01
Hi,

I have a windows 2003 file system which after a crash and chkdsk has resulted in some existing files having a 0kb size. I need a to create a list of filenames and paths for these files for potential recovery.

Does anyone have a script out there that does this?

Thx
Sjumu
0
Comment
Question by:sjumu
  • 2
4 Comments
 
LVL 2

Expert Comment

by:alphaphaedrus
Comment Utility
Dim folderPath, maxFileAge, countFiles

folderPath = Wscript.Arguments(0)
maxFileAge = Wscript.Arguments(1)
countFiles = 0

Set fs = WScript.CreateObject ("Scripting.FileSystemObject")
Set folder = fs.GetFolder(folderPath)

For Each file In folder.Files
     If file.Size = 0 And DateDiff("n", file.DateLastModified, Now()) > Int(maxFileAge) Then
          countFiles = countFiles + 1
     End If
Next

If countFiles > 0 Then
     WScript.Echo "Message: There are empty files older than " & maxFileAge & " minutes"
     WScript.Echo "Statistic: " & countFiles
     WScript.Quit( 1 )
Else
     WScript.Echo "Message: There are no empty files older than " & maxFileAge & " minutes"
     WScript.Echo "Statistic: " & countFiles
     WScript.Quit( 0 )
End If
0
 

Author Comment

by:sjumu
Comment Utility
Hi  alphaphaedrus,

Thanks for the quick reply, I put the script into a .wsf  files and tried to run it
but I get errors about  "Unterminated entity reference -  matching ';' not found"

Am I doin something wrong here?

sjumu
0
 
LVL 39

Accepted Solution

by:
footech earned 400 total points
Comment Utility
If you're open to PowerShell, this should work for you.
Get-ChildItem -path c:\ -force -recurse | where {$_.length -eq 0}

Open in new window

Just change the path to where you want to search.  With the recurse parameter it will search all subfolders.  An error will be displayed for any files that you don't have access to.  If you don't want those errors displayed you can change the command to
Get-ChildItem -path c:\ -force -recurse -ea SilentlyContinue | where {$_.length -eq 0}

Open in new window

0
 

Author Comment

by:sjumu
Comment Utility
Footech,

This is great!! exactly what I needed after I installed Powershell on the 2k3 server I could do so much more. I was able to pipe you code further to give me the full liast of paths for each file  and write to a log

Get-ChildItem -path c:\ -force -recurse | where {$_.length -eq 0}  |Select-Object -Property FullName

Many Thanks

sjumu
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now