Created
August 29, 2013 10:04
-
-
Save axelpale/6376313 to your computer and use it in GitHub Desktop.
Python script to list files of zero size. Takes in a filepath of a textfile containing a list of filepaths
and looks if the list contains files with filesize of zero. The filepaths of files with zero size are stored to file named
the original filepath of the list prefixed _zeros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
List files of zero size. | |
Takes in a filepath of a textfile containing a list of filepaths | |
and looks if the list contains files with filesize of zero. | |
The filepaths of files with zero size are stored to file named | |
the original filepath of the list prefixed _zeros | |
Example Usage | |
> cat listfile | |
/home/me/foo_666B.txt | |
/home/me/bar_420B.txt | |
/home/me/baz_0B.txt | |
> python findzeros.py listfile | |
> cat listfile_zeros | |
/home/me/baz_0B.txt | |
Author | |
Akseli Palen <[email protected]> | |
Version | |
2013-08-29 | |
Used with | |
python 2.7.3 | |
""" | |
import os | |
def findzeros(listfilepath): | |
zerolist = open(listfilepath + '_zeros', 'a') | |
with open(listfilepath) as f: | |
# http://stackoverflow.com/a/12330535/638546 | |
filepaths = f.read().splitlines() | |
for fp in filepaths: | |
fsize = os.path.getsize(fp) | |
if fsize == 0: | |
zerolist.write(fp + '\n') | |
zerolist.close() | |
if __name__ == "__main__": | |
import sys | |
abs_filepath = os.path.abspath(sys.argv[1]) | |
findzeros(abs_filepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment