Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Unable to Rename Copied Files via Windows Command Line  (Read 3114 times)

0 Members and 1 Guest are viewing this topic.

83dons

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Unable to Rename Copied Files via Windows Command Line
    « on: October 13, 2015, 09:43:34 AM »
    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.

    83dons

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 7
      Re: Unable to Rename Copied Files via Windows Command Line
      « Reply #1 on: October 13, 2015, 09:59:47 AM »
      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"