我正在加密一個檔案,它加密到一個名為 mark 的檔案夾,但我希望該檔案加密并放置在一個名為 Kevin 的子檔案夾中。代碼如下:
with open("encrypted_" filename '.txt', "wb") as ef:
ef.write(encrypted_file)
這會加密檔案,但將其放在同一個檔案夾中。我如何編輯它以便在加密后移動到 Kevin 檔案夾。我正在使用 Python。
謝謝
uj5u.com熱心網友回復:
像這樣的東西應該作業:
import os
# Create the folder
dir_name = "Kevin"
os.mkdir(dir_name)
# write the file in the folder
with open(dir_name "/encrypted_" filename '.txt', "wb") as ef:
ef.write(encrypted_file)
uj5u.com熱心網友回復:
如果使用linux,請嘗試加密后移動:
import shutil
shutil.move("origin_path", "destination_path")
uj5u.com熱心網友回復:
import shutil
with open("encrypted_" filename '.txt', "wb") as ef:
ef.write(encrypted_file)
shutil.move(f"encrypted_{filename}.txt", "Kevin") #f"encrypted_{filename}.txt" is the file and "Kevin" is the Destination Folder
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/519774.html
標籤:Python安全密码学
上一篇:如何獲取最大值不重復的行的索引?
