gpt4 book ai didi

batch-file - 如何复制和重命名

转载 作者:行者123 更新时间:2023-12-04 04:52:48 25 4
gpt4 key购买 nike

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

最佳答案

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

或更一般地说:
copy "%sourcefolder%\%sourcefile%" "%targetfolder%\New_%sourcefile%"

关于batch-file - 如何复制和重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17185486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com