Last active
August 29, 2015 14:14
-
-
Save asserchiu/32dcfe9d2bdec2a19c22 to your computer and use it in GitHub Desktop.
Zero fill all files ends with .secrete using python3
This file contains hidden or 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
#!/usr/bin/env python | |
# Tested in: | |
# Windows 8.1 Enterprise, en_US | |
# Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) | |
# [MSC v.1600 32 bit (Intel)] on win32 | |
import os | |
import sys | |
def fillZero(filename): | |
print(filename) | |
zeros = '\0' * os.path.getsize(filename) | |
with open(filename, 'w') as f: | |
f.write(zeros) | |
print('---> filled with {} zeros!'.format(os.path.getsize(filename))) | |
if __name__ == '__main__': | |
# print(str(sys.argv)) | |
if len(sys.argv) > 1: | |
# for fileName in sys.argv[1:]: | |
# fillZero(fileName) | |
print('Executing the program({}) with extra arguments is not tested.' | |
.format(str(sys.argv[0]))) | |
print('Feel free to fork it and complete it.') | |
else: | |
# print(str(sys.argv[0]), "<file1> <file2> ...") | |
try: | |
ends = '.secrete' | |
print('Zero fill all files ends with', ends) | |
for fileName in os.listdir("./"): | |
if fileName.endswith(ends): | |
fillZero('./' + fileName) | |
print('Done!') | |
except UnicodeEncodeError: | |
print('UnicodeEncodeError!', | |
'Run `chcp 65001` in this CMD and try again.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For convenience, you can create a
fillZero.bat
file and fill it with: