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
Solved

Script to List 0kb files

Posted on 2013-01-30
4
639 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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