Solved

Script to List 0kb files

Posted on 2013-01-30
4
663 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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