|
Answer» I am trying to create a .BAT script that will read a list of file locations from a CSV (in column 1) and then find that file in a directory and COPY it to a new folder giving it the name specified in column 2 of the CSV file.
The CSV looks like:
U:\source\OHSVols180\A100\B100\C107\F109.DOC,file1 U:\source\OHSVols180\A100\B100\C110\F152.PDF,file2
The .BAT file below currently works in that it accesses the CSV field 1 and copies the file to the new folder. My question is how do I manage to also rename the copied file as per column 2 in the CSV? It can keep the same file extension as previously listed in column 1. At the moment he files are NAMED as ORIGINALLY F109.DOC and F152.PDF but I want them to be called file1.DOC and file2.PDF.
Code: [Select]for /f "tokens=1 delims=," %%L in (U:\ExportList.csv) do copy "%%L" U:\Exported\ Any help greatly appreciated. Not sure how to REFERENCE the second part of the CSV and what code to put to rename the file.Have found the answer below!
Code: [Select]for /f "tokens=1,2 delims=," %%L in (U:\ExportList.csv) do copy "%%L" "U:\Exported\%%M%%~xL"
|