From b512571b66899c26d598aa457fe35bdc25b34183 Mon Sep 17 00:00:00 2001 From: halliday Date: Thu, 14 Dec 2023 10:04:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 复制奇偶数文件的脚本/copy_files.py | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 复制奇偶数文件的脚本/copy_files.py diff --git a/复制奇偶数文件的脚本/copy_files.py b/复制奇偶数文件的脚本/copy_files.py new file mode 100644 index 0000000..1c56851 --- /dev/null +++ b/复制奇偶数文件的脚本/copy_files.py @@ -0,0 +1,73 @@ +#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() +