Solved

Script to List 0kb files

Posted on 2013-01-30
4
648 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
ID: 38835632
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
ID: 38835931
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 40

Accepted Solution

by:
footech earned 400 total points
ID: 38836072
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
ID: 38843133
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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