如何在 Windows 中使用批处理重命名文件夹



我是批处理编程的新手,使用MacBook进行编码,因此无法运行这段应该重命名文件夹的代码。

谁能帮助我知道它是否成功重命名文件夹?如果没有,请给出可能的解决方案。

@echo off
echo Rename a Folder
set /p ON=Name of the folder to rename:
set /p NN=New folder name:
ren %ON% %NN%
echo a folder has been renamed
pause

您可以通过使用双引号并检查输入来减少潜在问题,从而使脚本更好。

@Echo Off
Echo Rename a folder
:OldName
ClS
Set "ON="
Set /P "ON=Name of the folder to rename: "
If Not "%ON%"=="" (If Exist "%ON%" (GoTo NewName
    ) Else Echo The folder was not found)
Echo Please try again!
Pause
GoTo OldName
:NewName
ClS
Set "NN="
Set /P "NN=New folder name: "
If "%ON%"=="" GoTo NewName
If Exist "%NN%" (Echo The folder %NN% already exists
    Pause
    GoTo NewName) Else (Ren "%ON%" "%NN%" && (Echo %ON% has been renamed) || (
        Echo An error occurred renaming %ON%)
    Pause)

您正在请求用户输入,该用户可以将他们想要的任何内容放入该输入提示中。使其强大的唯一方法是确保您完全满足任何可能的输入!

最新更新