75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
import shutil
|
||
import sys
|
||
import os
|
||
|
||
"""
|
||
69-477326 :: 版本: 1 :: 文件内部处理频繁切换,防止溢出测试
|
||
|
||
使用方法:
|
||
1.先用WriteFile 2.0.exe 工具生成一个 test.txt
|
||
2.和这个脚本放在一个目录中
|
||
3.执行脚本:
|
||
python copy_files.py args
|
||
args:
|
||
init # 初始化目录,会创建60个目录,有的会先删除
|
||
clean # 清楚创建的目录
|
||
js # 生成 test_1.txt,test_3.txt ...,并依次放入上述目录中
|
||
os # 生成 test_2.txt,test_4.txt ...,并依次放入上述目录中
|
||
"""
|
||
|
||
# 定义公共的部分
|
||
path = os.getcwd()
|
||
file_path = os.path.join(path, 'test.txt')
|
||
dir_list = list(range(1, 61))
|
||
|
||
# 复制奇数
|
||
def jishu():
|
||
file_list = list(range(121))[1::2]
|
||
fd = dict(zip(file_list, dir_list))
|
||
copy_file(fd)
|
||
|
||
# 复制偶数
|
||
def oushu():
|
||
file_list = list(range(121))[2::2]
|
||
fd = dict(zip(file_list, dir_list))
|
||
copy_file(fd)
|
||
|
||
# 复制文件到目录中
|
||
def copy_file(fd):
|
||
for file, dir in fd.items():
|
||
newname = 'test_' + str(file) + '.txt'
|
||
todir = os.path.join(path, str(dir), newname)
|
||
shutil.copyfile(file_path, todir)
|
||
|
||
# 初始化目录
|
||
def init_dir():
|
||
for dir in dir_list:
|
||
dir_path = os.path.join(path, str(dir))
|
||
if os.path.exists(dir_path):
|
||
shutil.rmtree(dir_path)
|
||
os.mkdir(dir_path)
|
||
|
||
def clean():
|
||
for dir in dir_list:
|
||
dir_path = os.path.join(path, str(dir))
|
||
if os.path.exists(dir_path):
|
||
shutil.rmtree(dir_path)
|
||
|
||
|
||
if __name__ == '__main__':
|
||
# 定义传参
|
||
if len(sys.argv) != 2:
|
||
assert False, 'not get args'
|
||
|
||
if sys.argv[1] not in ["js", "os", "init","clean"]:
|
||
assert False, 'args is error,please input js or os '
|
||
|
||
if sys.argv[1] == 'init':
|
||
init_dir()
|
||
elif sys.argv[1] == 'js':
|
||
jishu()
|
||
elif sys.argv[1] == 'os':
|
||
oushu()
|
||
elif sys.argv[1] == 'clean':
|
||
clean()
|