odesk

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# coding: utf-8
from __future__ import division, print_function, unicode_literals
import argparse
import os
# default value
file_size = 1024 * 1024 * 2 # 2mb
new_files_size = 10
path = '.'
def check_file(path):
if os.path.getsize(path) >= file_size:
print('I will remove: ' + path)
with open(path, 'w') as outfile:
outfile.write(dump_text)
def search_files(path):
for _, _, files in os.walk(path):
for name in files:
check_file(name)
parser = argparse.ArgumentParser()
parser.add_argument(
"-path", type=str, help="Start path for search", default=path, nargs='?')
parser.add_argument(
"-size", type=int, help="Low bound of file size", default=file_size, nargs='?')
parser.add_argument(
"-size_new", type=int, help="Size for new files", default=new_files_size, nargs='?')
args = parser.parse_args()
file_size = int(args.size)
if '__main__' == __name__:
dump_text = ' ' * int(args.size_new)
search_files(str(args.path))