我有一个bat文件,可根据用户输入创建文件夹和子文件夹。我想代码告诉我它正在尝试创建的文件夹已经存在,而且(如果可能的话),如果文件夹已经存在,我希望代码将子文件夹复制到预先存在的文件夹中。
我的代码 -
@echo off
echo.
:EnterName
set "dest=""
set /P "dest=Enter Name: "
set "dest=%dest:"=%"
if "%dest%" == "" cls & goto EnterName
set "findest=Z:\ProjectIT\copy\%dest%"
robocopy Z:\ProjectIT\copy\xcopy "%findest%" /e /NFL /NDL /NJH /NJS
echo Construction folder has been created for "%dest%"
echo.
pause
希望有道理!
答案 0 :(得分:0)
您要查找的命令是if exist
:
@echo off
echo.
:EnterName
set "dest=""
set /P "dest=Enter Name: "
set "dest=%dest:"=%"
if "%dest%"=="" cls & goto EnterName
if exist %findest% (
echo This folder already exists!
echo All subfolders will be copied to the existing folder.
)
set "findest=Z:\ProjectIT\copy\%dest%"
robocopy Z:\ProjectIT\copy\xcopy "%findest%" /e /NFL /NDL /NJH /NJS
echo Construction folder has been created for "%dest%"
echo.
pause
您无需修改代码即可复制子文件夹。如果该文件夹存在,则所有内容都将被复制到其中。