Remco
2015-05-19 12:20:03 UTC
Hello,
I am new here, and new with Python.
I use Python 2.7 on a windows computer in Pyscripter.
I've got the next problem witch I need some help with:
I need to copy several files, from several folders to a new location in the same folder structure as they are now.
And all the files I need to copy are in a text (.txt) file.
The source folder looks like this: (with in some cases even sub-folders or sub-sub-folders)
D:\source\folder1
D:\source\folder2
D:\source\folder3
D:\source\folder4
D:\source\folder5
And the list.txt looks like this: (over 250 entries in the original list file) D:\source\folder1\1.jpg D:\source\folder1\2.jpg D:\source\folder1\text3.txt D:\source\folder1\FLD\pic.tif
In every source folder there different kind of extensions that I need to copy.
I have written the script below, with the help of google, and the only action I see is the missings.txt that is produced.
With in it all the files that are not copied.
import os
import shutil
target_dir = r'D:\target\'
source_dir = r'D:\source\'
source_file = r'D:\source\list.txt'
missing_files = open("missings.txt","w")
for line in open('list.txt'):
source_file = os.path.normpath(source_dir +line)
target_file = os.path.normpath(target_dir +line)
if os.path.exists(target_file):
shutil.copyfile(source_file,target_file)
else:
missing_files.write(line)
missing_files.close()
Can someone help my fixing my problem.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
I am new here, and new with Python.
I use Python 2.7 on a windows computer in Pyscripter.
I've got the next problem witch I need some help with:
I need to copy several files, from several folders to a new location in the same folder structure as they are now.
And all the files I need to copy are in a text (.txt) file.
The source folder looks like this: (with in some cases even sub-folders or sub-sub-folders)
D:\source\folder1
D:\source\folder2
D:\source\folder3
D:\source\folder4
D:\source\folder5
And the list.txt looks like this: (over 250 entries in the original list file) D:\source\folder1\1.jpg D:\source\folder1\2.jpg D:\source\folder1\text3.txt D:\source\folder1\FLD\pic.tif
In every source folder there different kind of extensions that I need to copy.
I have written the script below, with the help of google, and the only action I see is the missings.txt that is produced.
With in it all the files that are not copied.
import os
import shutil
target_dir = r'D:\target\'
source_dir = r'D:\source\'
source_file = r'D:\source\list.txt'
missing_files = open("missings.txt","w")
for line in open('list.txt'):
source_file = os.path.normpath(source_dir +line)
target_file = os.path.normpath(target_dir +line)
if os.path.exists(target_file):
shutil.copyfile(source_file,target_file)
else:
missing_files.write(line)
missing_files.close()
Can someone help my fixing my problem.
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor