Kenny
asked on
Read a text file and copy each file to a different folder and rename it
Hi,
I need to copy thousands of image files from multiple folders on our server (within 1 main folder) to a new folder and rename it accordingly. All the details are in a text file (saved as tab delimited from an excel sheet) with the following format (excerpt from the actual file) :
\\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0001-40 3.GIF \\192.168.1.118\Picture\B2 B-IT\16286 9_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0001-50 1-B.JPG \\192.168.1.118\Picture\B2 B-IT\16287 1_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0002-05 0.JPG \\192.168.1.118\Picture\B2 B-IT\16287 8_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0003-11 6.JPG \\192.168.1.118\Picture\B2 B-IT\16292 6_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-B1\0 003-114-B1 .JPG \\192.168.1.118\Picture\B2 B-IT\16292 7_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0003-11 6.JPG \\192.168.1.118\Picture\B2 B-IT\16292 8_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-B1\0 003-114-B1 .JPG \\192.168.1.118\Picture\B2 B-IT\16292 9_1.jpg
\\192.168.1.118\PICTURE\0- PKG\0-B1\0 003-114-B2 .JPG \\192.168.1.118\Picture\B2 B-IT\16292 9_2.jpg
I have mapped the \\192.168.1.118\PICTURE\ folder as P-drive on my PC (from which I hope to run the script) if that is any help. To make it easier to understand, let me give an example here.
For first line line : \\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0001-40 3.GIF \\192.168.1.118\Picture\B2 B-IT\16286 9_1.jpg
The script would need to copy \\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0001-40 3.GIF to folder \\192.168.1.118\Picture\B2 B-IT\ and rename the file to 162869_1.jpg
I assume that if typed out, it would be
copy \\192.168.1.118\PICTURE\0- PKG\0-PVCB AG\0001-40 3.GIF \\192.168.1.118\Picture\B2 B-IT\16286 9_1.jpg
However, due to the sheer magnitude of files I am unable to do this manually. I am not familiar with windows scripting. It would be great if I could be pointed to a site where I could refer easily for accurate and comprehensive information about windows scripting.
The server is a physical server running Windows 2008 R2 SP1. Please do let me know if you require more information.
Thank you.
Regards,
Kenny
I need to copy thousands of image files from multiple folders on our server (within 1 main folder) to a new folder and rename it accordingly. All the details are in a text file (saved as tab delimited from an excel sheet) with the following format (excerpt from the actual file) :
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
\\192.168.1.118\PICTURE\0-
I have mapped the \\192.168.1.118\PICTURE\ folder as P-drive on my PC (from which I hope to run the script) if that is any help. To make it easier to understand, let me give an example here.
For first line line : \\192.168.1.118\PICTURE\0-
The script would need to copy \\192.168.1.118\PICTURE\0-
I assume that if typed out, it would be
copy \\192.168.1.118\PICTURE\0-
However, due to the sheer magnitude of files I am unable to do this manually. I am not familiar with windows scripting. It would be great if I could be pointed to a site where I could refer easily for accurate and comprehensive information about windows scripting.
The server is a physical server running Windows 2008 R2 SP1. Please do let me know if you require more information.
Thank you.
Regards,
Kenny
ASKER
Wow... that was so simple and it worked. Thank you. Unfortunately I missed out 1 detail. The extension is all .jpg in the inputfile. I know that rubbish in equals rubbish out, and I will be giving you the points tomorrow even if you do not help further.
However, is it a lot of work to modify the script to maintain the same extension that was used in the original filename as the extension for the new filename (ignoring the new file extension in the input file?). All extensions are 3 characters only. It would be quite time-consuming for me to change all the wrong extensions in the inputfile as there are over 13,900 records, with many gif and png extensions in addition to jpg.
Thanks so much.
However, is it a lot of work to modify the script to maintain the same extension that was used in the original filename as the extension for the new filename (ignoring the new file extension in the input file?). All extensions are 3 characters only. It would be quite time-consuming for me to change all the wrong extensions in the inputfile as there are over 13,900 records, with many gif and png extensions in addition to jpg.
Thanks so much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much
Just change the input file path, and verify that in line 7, there is actually a "tab" character after copying from here.
Open in new window
And for something more modern, here's the PowerShell version:
Open in new window