你有沒有人知道如何從一個目錄複製文件到另一個?我使用了它的「shutil.copy2」,並將副本獲取到指定的輸出。從一個目錄複製文件到另一個python
雖然,我的目標是能夠將文件從一個目錄複製到另一個目錄,允許用戶指定他們想要按名稱複製的文件。而不是每次都輸入目錄路徑。
思考過程:因爲我指定了文件目錄。不知何故,使用raw_input用戶可以指定他們想從指定目錄複製哪個文件。發佈我的代碼以供參考。 #請不要BS評論我是剛接觸編程,只是想學習。
#----------------------------------------------------------------------------------------------------------------#
# These params will be used for specifying which template you want to copy and where to output
#----------------------------------------------------------------------------------------------------------------#
'''Load file from x directory into current working directory '''
#PullTemplate: Specify which template you want to copy, by directory path
TemplateRepo = ("/home/hadoop/BackupFolders/Munge_Stage_Templates/Templates")
user_input = raw_input("which file do you want to pull:")
#OutputTemplate: Let's you specify where you want to output the copied template.
#Originally set to your current working directory (u".")
OutputTemplate = (u".")
#----------------------------------------------------------------------------------------------------------------#
# STATIC CODE: Do not alter "Just Run!"
#----------------------------------------------------------------------------------------------------------------#
shutil.copy2(TemplateRepo, OutputTemplate)
的可能的複製[如何將Python中的文件](http://stackoverflow.com/questions/8858008/how-to-move-a-file-in-python) – JoeBeCool