# -*- coding: utf-8 -*- #添加垃圾文件 import os import sys import random py_path = sys.argv[0][::-1].split('/',1)[1][::-1]+'/' os.chdir(py_path) # out_file_path = sys.argv[1] class_files_list = [] class_key_list = ["Class","Def","Layer","Unit","Component","Pic","Manager","Data"] with open('FileNames') as file: content = file.read() class_files_list = content.split("\n") def del_files(dir_path): for root, dirs, files in os.walk(dir_path, topdown=False): for name in files: os.remove(os.path.join(root, name)) # 删除文件 for name in dirs: os.rmdir(os.path.join(root, name)) # 删除一个空目录 def mk_sub_file(file_prefix, buf): dst_file_path = out_file_path + '/' + file_prefix with open(dst_file_path,'wb') as fout: fout.write(buf) def add_files(): if not os.path.exists(out_file_path): os.mkdir(out_file_path) del_files(out_file_path) repeat_times = 10 while repeat_times>0: for x in xrange(1,random.randint(2,4)): lenght = len(class_files_list) class_name = class_files_list[random.randint(0,lenght)] key = class_key_list[random.randint(0,len(class_key_list) - 1)] rep_str = class_name[random.randint(0,len(class_name) - 1)] class_name = class_name.replace(rep_str,key) mk_sub_file(class_name,class_name + key + rep_str + class_name) pass repeat_times = repeat_times - 1 print("add unused files ok") if __name__=="__main__": add_files()