Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Created July 6, 2017 06:00
Show Gist options
  • Save erinxocon/acb86453685437e72190d30264415543 to your computer and use it in GitHub Desktop.
Save erinxocon/acb86453685437e72190d30264415543 to your computer and use it in GitHub Desktop.
A small directory walker that uses delegator.py to clean up some binary files
import os
import delegator
rootdir = '.'
for dirName, subdirlist, fileList in os.walk(rootdir):
print('Found Directory: {0}'.format(dirName))
for name in fileList:
if name.lower().endswith('.job'):
file_name = '{0}/{1}'.format(dirName, name)
print('\tFile Found: {0}'.format(name))
c = delegator.run('strings {0}'.format(file_name))
with open(file_name.replace('.JOB', '.txt'), 'w') as out_file:
out_file.write(c.out)
print (c.out)
d = delegator.run('rm {0}'.format(file_name))
@erinxocon
Copy link
Author

This doesn't check for correct paths or assemble correct paths using os.path(). It operates on a local basis only, be careful or the rm could remove unintended files! Thanks to @kennethreitz for delegator.py for easy use of the gnu utility strings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment