2

我想通过"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
4

2 回答 2

3
copy "C:\Users\Niki\Desktop\report\Expenses_2013" "%targetfolder%\New_Expenses_2013"

或更一般地说:

copy "%sourcefolder%\%sourcefile%" "%targetfolder%\New_%sourcefile%"
于 2013-06-19T08:00:00.433 回答
0

步骤 1:复制文件
在命令提示符下,键入:

COPY "C:\Users\Niki\Desktop\report\*" "%TargetFolder%\*"

第 2 步:重命名
类型:

REN * NEW_*
于 2013-06-19T07:45:54.290 回答