python - How to copy a file from a network share to local disk with variables? -
if use following line:
shutil.copyfile(r"\\mynetworkshare\myfile.txt","c:\temp\myfile.txt")   everything works fine. however, can't seem figure out how use variable network share path, because need 'r' (relative?) flag. end result imagine like:
source_path = "\\mynetworkshare" dest_path = "c:\temp" file_name = "\\myfile.txt"  shutil.copyfile(r source_path + file_name,dest_path + file_name)   but have had no luck different variations of approach.
the r used in first code example making string "raw" string. in example, means string see backslashes , not try use them escape \\ \.
to second code sample working, you'd use r on strings, , not in copyfile command:
source_path = r"\\mynetworkshare" dest_path = r"c:\temp" file_name = "\\myfile.txt"  shutil.copyfile(source_path + file_name, dest_path + file_name)      
Comments
Post a Comment