我想通过"New_"
在复制文件的原始文件名之前添加(可变文本)来重命名文件。
示例:文件"Expenses_2013"
从"C:\Users\Niki\Desktop\report"
复制到"TargetFolder"
并重命名为"NEW_Expenses_2013"
. 文件名"Expenses_2013"
不是静态的..它是变量。我有以下命令。我想编辑这个命令。
call :CopyandRename "C:\Users\Niki\Desktop\report" "%TargetFolder%\"
新编辑
@echo off
setlocal
Set TargetFolder=C:\Users\Niki\Desktop\Final Report
call :copyAndRename "C:\Users\Niki\Desktop\Report" "%Targetfolder%\"
:: Done
goto :eof
:copyAndRename
set SourceFolder=%~1
set TargetFile=%~2
:: Find the newest file in the source folder
for /f "tokens=*" %%F in ('dir /b /od /a-d "%SourceFolder%"') do set "NewestFile=%%F"
:: copy and rename it to the target
copy "%SourceFolder%\%NewestFile%" "%TargetFile%"
pause
:: Done with this subroutine
goto :eof