File copy and renaming

久未见 提交于 2019-12-23 15:42:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!