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

How to Rename a Folder using Batch-Processing in Windows?

我是Batch编程的新手,用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)

您要求用户输入,该用户可以将他们想要的任何内容放入该输入提示中。使这种健壮的唯一方法是确保您完全满足任何可能的输入!