簡單編寫的檔案複製模組python指令碼

2021-08-14 09:57:10 字數 1035 閱讀 5538

sourcefilename = input("請輸入你要複製的檔名:")

index = sourcefilename.rfind(".") # 除用字串的內建函式外,還可以使用條件語句判斷

copyfilename = sourcefilename[:index]+ "-副本"+sourcefilename[index:]

readfile = open(sourcefilename,"rb")

content = readfile.read()

writefile = open(copyfilename,"wb")

writefile.write(content)

print("檔案複製完成...")

readfile.flush()

writefile.flush()

readfile.close()

writefile.close()

sourcefilename = input("請輸入你要複製的檔名:")

liststr = sourcefilename.split(".")

copyfilename = liststr[0] +"-副本."+liststr[1] # 以防檔案命名格式不正確做出的改變

readfile = open(sourcefilename,"rb")

writefile = open(copyfilename,"wb")

while true:

content = sourcefilename.read(1024*1024) #read()的單位為byte,讓其以1mb傳輸

if len(content)==0:

break

writefile.write(content)

writefile.flush()

print("檔案複製完成...")

readfile.close()

writefile.close()

歡迎各位補充和糾錯

nginx 編寫簡單handler模組

1 安裝依賴庫 安裝gcc g 的依賴庫 apt get install build essential apt get install libtool 安裝pcre依賴庫 sudo apt get install libpcre3 libpcre3 dev 安裝zlib依賴庫 apt get in...

Python常用模組 檔案複製模組shutil

高階的檔案 資料夾 壓縮包處理模組 shutil.copyfileobj fsrc,fdst 將檔案內容拷貝到另乙個檔案中 import shutil shutil.copyfileobj open old.xml r open new.xml w shutil.copyfile src,dst 拷...

os模組之複製檔案

乙個簡單的例子,刪除乙個指定的檔案。import os,sys def copyfile sourdir,targetdir,name 3個引數 sourdir是源目錄,targetdir是目標目錄,name是要複製的檔案 for files in os.listdir sourdir if fil...