2016-11-21 40 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

感谢您的回答 –

相关问题