使用批处理脚本重命名文件夹

时间:2022-05-15 00:25:21

I am currently trying to Rename the Folder that was recently created, i know there is a command called REN (or) RENAME but it is used to rename a file and not the Folder.

我目前正在尝试重命名最近创建的文件夹,我知道有一个名为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%"
    )

How to achieve this.?

如何实现这一目标。

1 个解决方案

#1


3  

In your batch code in line starting with if exist the command ren is started just with 1 parameter. So the second parameter with new name for folder/file is missing. Please note that the second parameter must be always just the new name of file/folder without path.

在您的批处理代码中,如果存在,则只使用1个参数启动命令ren。因此缺少具有文件夹/文件新名称的第二个参数。请注意,第二个参数必须始终只是没有路径的文件/文件夹的新名称。

Your batch code should be most likely:

您的批代码应该是最有可能的:

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%"
)

#1


3  

In your batch code in line starting with if exist the command ren is started just with 1 parameter. So the second parameter with new name for folder/file is missing. Please note that the second parameter must be always just the new name of file/folder without path.

在您的批处理代码中,如果存在,则只使用1个参数启动命令ren。因此缺少具有文件夹/文件新名称的第二个参数。请注意,第二个参数必须始终只是没有路径的文件/文件夹的新名称。

Your batch code should be most likely:

您的批代码应该是最有可能的:

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%"
)