Copy and rename file

I want to copy the files below from one place to another. After copying the file, I want to add something to the file name.

From C: \ Users \ Niki \ Desktop * .csv To C: \ Users \ Niki \ reports \ Final _ *. Csv

How can I do it? To do this, I use the command below:

copy /-y "C:\Users\Niki\Desktop\*.csv" "%TargetFolder%" 
+4
source share
3 answers

Here is the batch file that should work:

 @echo off set "targetfolder=d:\backup" for %%a in ("C:\Users\Niki\Desktop\*.csv") do ( copy /-y "%%a" "%TargetFolder%\Final_%%~nxa" ) 
+4
source
 for %%x in ("C:\Users\Niki\Desktop\*.csv") do copy "%%~fx" "C:\Users\Niki\reports\Final_%%~nxx" 
+2
source

Perhaps I do not understand your question, but can you just specify the file name at the end of the destination directory?

 copy /-y "C:\Users\Niki\Desktop\xyz.csv" "%TargetFolder%\Final_xyz.csv" 
0
source

Source: https://habr.com/ru/post/1486618/


All Articles