74 lines
1.6 KiB
Python
74 lines
1.6 KiB
Python
#encoding=utf-8
|
||
import shutil
|
||
import sys
|
||
|
||
from pathlib import Path
|
||
|
||
"""
|
||
69-477326 :: 版本: 1 :: 文件内部处理频繁切换,防止溢出测试
|
||
|
||
使用方法:
|
||
1.先用WriteFile 2.0.exe 工具生成一个 test.txt
|
||
2.和这个脚本放在一个目录中
|
||
3.执行脚本:
|
||
python copy_files.py args
|
||
args:
|
||
init # 初始化目录,会创建60个目录,有的会先删除
|
||
js # 生成 test_1.txt,test_3.txt ...,并依次放入上述目录中
|
||
os # 生成 test_2.txt,test_4.txt ...,并依次放入上述目录中
|
||
"""
|
||
|
||
|
||
|
||
|
||
#定义公共的部分
|
||
path = Path.cwd()
|
||
file_path = 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 = path / str(dir) / newname
|
||
shutil.copyfile(file_path, todir)
|
||
|
||
#初始化目录
|
||
def init_dir():
|
||
for dir in dir_list:
|
||
dir_path = path / str(dir)
|
||
if dir_path.exists():
|
||
shutil.rmtree(dir_path)
|
||
dir_path.mkdir()
|
||
|
||
|
||
|
||
if __name__ == '__main__':
|
||
|
||
#定义传参
|
||
if len(sys.argv) != 2:
|
||
assert False,'not get args'
|
||
|
||
if sys.argv[1] not in ["js","os","init"]:
|
||
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()
|
||
|