2016-11-21 84 views
0

如何從c:/users/robert/appdata/OpenOffice/work.txt中將文件從這裏複製到執行python腳本的文件夾中?而不用在python腳本中添加文件夾名稱(羅伯特)?Python從appdata複製一個文件

from shutil import copyfile 
 

 
copyfile(src, dst)

回答

0
import getpass,shutil,os 
src="C:\Users\%s\AppData\OpenOffice\work.txt" %(getpass.getuser()) 

dest=os.getcwd() 
def copyFile(src, dest): 
    try: 
     shutil.copy(src, dest) 
     print("Done") 
    # eg. src and dest are the same file 
    except shutil.Error as e: 
     print('Error: %s' % e) 
    # eg. source or destination doesn't exist 
    except IOError as e: 
     print('Error: %s' % e.strerror) 

copyFile(src,dest) 
+0

感謝您的回答 –

相關問題