问题
I want to copy below files from one location to another. After copy file I want to add something in file name.
From C:\Users\Niki\Desktop*.csv To C:\Users\Niki\reports\Final_*.csv
How would I do that? I am using below command for this:
copy /-y "C:\Users\Niki\Desktop\*.csv" "%TargetFolder%"
回答1:
Here's a 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"
)
回答2:
for %%x in ("C:\Users\Niki\Desktop\*.csv") do copy "%%~fx" "C:\Users\Niki\reports\Final_%%~nxx"
回答3:
Perhaps I am misunderstanding your question but can you not just specify the file name at the end of your destination directory?
copy /-y "C:\Users\Niki\Desktop\xyz.csv" "%TargetFolder%\Final_xyz.csv"
来源:https://stackoverflow.com/questions/17148213/file-copy-and-renaming