输入回车的时候,也执行1和2的功能
时间: 2024-04-14 12:29:40 浏览: 11
要在用户按下回车键时执行删除和复制的功能,你可以使用 `choice` 命令结合 `if` 条件判断。以下是修改后的批处理脚本:
```batch
@echo off
:menu
echo Please choose an option:
echo 1. Delete all files and folders in a specified directory
echo 2. Copy all files and folders from a specified directory to another location
echo Q. Quit
choice /c 12q /n /m "Enter your choice: "
if errorlevel 3 (
exit /b
) else if errorlevel 2 (
call :copy_files_and_folders
) else if errorlevel 1 (
call :delete_files_and_folders
) else (
call :delete_files_and_folders
call :copy_files_and_folders
)
goto :menu
:delete_files_and_folders
set /p delete_path=Enter the path to delete files and folders:
echo Deleting files and folders in %delete_path%...
del /s /q "%delete_path%\*.*"
for /d %%i in ("%delete_path%\*") do (
rd /s /q "%%i"
)
echo All files and folders deleted.
exit /b
:copy_files_and_folders
set /p source_path=Enter the source path to copy files and folders:
set /p destination_path=Enter the destination path to copy files and folders:
echo Copying files and folders from %source_path% to %destination_path%...
xcopy /s /y "%source_path%\*" "%destination_path%\"
echo All files and folders copied.
exit /b
```
现在,当用户按下回车键时,它会依次执行删除和复制操作。如果用户选择数字1或2,它也会执行相应的功能。