1 # -*- coding: utf-8-*-
2 import shutil
3 type = int(input("请选择需要复制类型(选择数字即可):1.文件夹,2.文件
"))
4 if type == 1:
5 try:
6 filePath = str(input("请输入复制文件路径:
"))
7 filename = str(input("请输入复制文件name:
"))
8 fmat = str(input("请输入文件格式:
"))
9 filePathNow = filePath + "\" + filename + fmat
10 print("copy文件地址:%s" % filePathNow)
11 num1 = float(input("请输入你有多帅(没有我帅,只能是数字不可以是数字1哦):
"))
12 for i in range(1,int(num1)):
13 num2 = str(i)
14 name = filename + num2 + fmat
15 copyFilePath = filePath + "\" + name
16 shutil.copyfile(filePathNow,copyFilePath)
17 except ValueError:
18 print('输入的不是数字。')
19 exit()
20 elif type == 2:
21 try:
22 filePath = str(input("请输入复制文件路径:
"))
23 filename = str(input("请输入复制文件name:
"))
24 filePathNow = filePath + "\" + filename
25 print("copy文件地址:%s" % filePathNow)
26 num1 = float(input("请输入你有多帅(没有我帅,只能是数字不可以是数字1哦):
"))
27 for i in range(1, int(num1)):
28 num2 = str(i)
29 name = filename + num2
30 copyFilePath = filePath + "\" + name
31 shutil.copyfile(filePathNow, copyFilePath)
32 except ValueError:
33 print('输入的不是数字。')
34 exit()
另还有批量bat复制文件和文件夹,可参考https://www.cnblogs.com/zwh-Seeking/p/11168815.html