Announcement

Collapse
No announcement yet.

Script to find 0 (zero) bytes file on file server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to find 0 (zero) bytes file on file server

    Hi - I need to write a script which will search my file server for any files that are 0 bytes in size. We have a very large file server and users have been finding 0 byte files in random folders. I would like to search and print out a report which will display all files in a drive with 0 bytes file size.

    Thzx

  • #2
    Re: Script to find ) bytes file on file server

    The Powershell way. Run from root dir.

    Code:
    gci -Recurse | % { # Get a recursive list of child items, that is, dir
      if(!$_.PSIsContainer -and $_.length -eq 0) { # If not directory and size is 0
        write-host ("{0}: {1}" -f $_.FullName, $_.length) # print name and size
       }
    }
    -vP

    Comment


    • #3
      Re: Script to find ) bytes file on file server

      That great thx!.. One more question.. How do i get that script to create a file / log (in notepad) of what it finds.. thx

      Comment


      • #4
        Re: Script to find 0 (zero) bytes file on file server

        To add content to a file, replace write-host with add-content, like so:

        Code:
        gci -Recurse | % { # Get a recursive list of child items, that is, dir
          if(!$_.PSIsContainer -and $_.length -eq 0) { # If not directory and size is 0
            add-content -path "c:/files-of-zero-length.log"-value ("{0}: {1}" -f $_.FullName, $_.length) # print name and size into a file
           }
        }
        -vP

        Comment


        • #5
          Re: Script to find 0 (zero) bytes file on file server

          Thanks!.. that worked grt.. Appreciate the code!

          Comment

          Working...
          X