[英]Renaming a Folder using Batch Script
我當前正在嘗試重命名最近創建的文件夾,我知道有一個名為REN(或)RENAME的命令,但是它用於重命名文件而不是文件夾。
Below is the code that i am working to achieve this.
for %%# in ("%mask%_*") do (
if not exist "%destination_dir%\%mask%" mkdir "%destination_dir%\%mask%"
move /y "%%~#" "%destination_dir%\%mask%"
if exist "%destination_dir%\%mask%" ren "%destination_dir%\%mask%_%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%"
)
如何實現這一目標?
在以if exist
開頭的批處理代碼中, ren命令僅從1個參數開始。 因此,缺少新名稱的文件夾/文件的第二個參數。 請注意,第二個參數必須始終只是不帶路徑的文件/文件夾的新名稱。
您的批處理代碼最有可能是:
for %%# in ("%mask%_*") do (
if not exist "%destination_dir%\%mask%" mkdir "%destination_dir%\%mask%"
move /y "%%~#" "%destination_dir%\%mask%"
if exist "%destination_dir%\%mask%" ren "%destination_dir%\%mask%" "%mask%_%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%"
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.