1 # -*- coding: utf-8-*- 2 import shutil 3 type = int(input("請選擇需要複製類型(選擇數字即可):1.文件夾,2.文件\n")) 4 if type == 1: 5 try: 6 filePath = str(input("請輸入複製文件路徑:\n")) 7 filename = str(input("請輸入複製文件name:\n")) 8 fmat = str(input("請輸入文件格式:\n")) 9 filePathNow = filePath + "\\" + filename + fmat 10 print("copy文件地址:%s" % filePathNow) 11 num1 = float(input("請輸入你有多帥(沒有我帥,只能是數字不可以是數字1哦):\n")) 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("請輸入複製文件路徑:\n")) 23 filename = str(input("請輸入複製文件name:\n")) 24 filePathNow = filePath + "\\" + filename 25 print("copy文件地址:%s" % filePathNow) 26 num1 = float(input("請輸入你有多帥(沒有我帥,只能是數字不可以是數字1哦):\n")) 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
shell/Python複製文件和文件夾
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.