from os.path import isdir, abspath, getsize, join
from os import listdir, system
filenames = []
def append_filename(path):
contents = listdir(abspath(path))
for content in contents:
content = join(path, content)
if isdir(content):
append_filename(abspath(content))
else:
filenames.append(abspath(content))
return filenames
def main():
path = input("[*] Please input the directory path:")
append_filename(path)
print(filenames)
for filename in filenames:
if getsize(filename) == 0:
system('del %s' % filename)
print("[-] Deleting %s ..." % filename)
if __name__ == '__main__':
main()
代码乱写,没优化