parent
5fd87d85c0
commit
6d31ba18c8
|
@ -1,8 +1,6 @@
|
||||||
#encoding=utf-8
|
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
69-477326 :: 版本: 1 :: 文件内部处理频繁切换,防止溢出测试
|
69-477326 :: 版本: 1 :: 文件内部处理频繁切换,防止溢出测试
|
||||||
|
@ -14,16 +12,14 @@ from pathlib import Path
|
||||||
python copy_files.py args
|
python copy_files.py args
|
||||||
args:
|
args:
|
||||||
init # 初始化目录,会创建60个目录,有的会先删除
|
init # 初始化目录,会创建60个目录,有的会先删除
|
||||||
|
clean # 清楚创建的目录
|
||||||
js # 生成 test_1.txt,test_3.txt ...,并依次放入上述目录中
|
js # 生成 test_1.txt,test_3.txt ...,并依次放入上述目录中
|
||||||
os # 生成 test_2.txt,test_4.txt ...,并依次放入上述目录中
|
os # 生成 test_2.txt,test_4.txt ...,并依次放入上述目录中
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 定义公共的部分
|
# 定义公共的部分
|
||||||
path = Path.cwd()
|
path = os.getcwd()
|
||||||
file_path = path / 'test.txt'
|
file_path = os.path.join(path, 'test.txt')
|
||||||
dir_list = list(range(1, 61))
|
dir_list = list(range(1, 61))
|
||||||
|
|
||||||
# 复制奇数
|
# 复制奇数
|
||||||
|
@ -42,26 +38,30 @@ def oushu():
|
||||||
def copy_file(fd):
|
def copy_file(fd):
|
||||||
for file, dir in fd.items():
|
for file, dir in fd.items():
|
||||||
newname = 'test_' + str(file) + '.txt'
|
newname = 'test_' + str(file) + '.txt'
|
||||||
todir = path / str(dir) / newname
|
todir = os.path.join(path, str(dir), newname)
|
||||||
shutil.copyfile(file_path, todir)
|
shutil.copyfile(file_path, todir)
|
||||||
|
|
||||||
# 初始化目录
|
# 初始化目录
|
||||||
def init_dir():
|
def init_dir():
|
||||||
for dir in dir_list:
|
for dir in dir_list:
|
||||||
dir_path = path / str(dir)
|
dir_path = os.path.join(path, str(dir))
|
||||||
if dir_path.exists():
|
if os.path.exists(dir_path):
|
||||||
shutil.rmtree(dir_path)
|
shutil.rmtree(dir_path)
|
||||||
dir_path.mkdir()
|
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 __name__ == '__main__':
|
||||||
|
|
||||||
# 定义传参
|
# 定义传参
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
assert False, 'not get args'
|
assert False, 'not get args'
|
||||||
|
|
||||||
if sys.argv[1] not in ["js","os","init"]:
|
if sys.argv[1] not in ["js", "os", "init","clean"]:
|
||||||
assert False, 'args is error,please input js or os '
|
assert False, 'args is error,please input js or os '
|
||||||
|
|
||||||
if sys.argv[1] == 'init':
|
if sys.argv[1] == 'init':
|
||||||
|
@ -70,4 +70,5 @@ if __name__ == '__main__':
|
||||||
jishu()
|
jishu()
|
||||||
elif sys.argv[1] == 'os':
|
elif sys.argv[1] == 'os':
|
||||||
oushu()
|
oushu()
|
||||||
|
elif sys.argv[1] == 'clean':
|
||||||
|
clean()
|
Loading…
Reference in New Issue