编写一个bat脚本,要求: 1、当输入数字1的时候,执行删除指定目录下所有文件和文件夹; 2、当输入数字2的时候,将指定目录下的所有文件和文件夹复制到另外一个指定位置,如有重复则直接覆盖,且不提醒; 3、当输入字母Q的时候,直接退出,不作任何处理; 4、当输入其他任何信息的时候,依次执行1和2中所述的两个功能 执行脚本时,需要提示上述的信息
时间: 2024-04-13 07:29:29 浏览: 160
批处理bat文件
以下是一个符合你要求的批处理脚本:
```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
set /p choice=Enter your choice:
if "%choice%"=="1" (
call :delete_files_and_folders
) else if "%choice%"=="2" (
call :copy_files_and_folders
) else if /i "%choice%"=="Q" (
exit /b
) 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时,会将指定目录下的所有文件和文件夹复制到另一个指定路径;当输入字母Q时,脚本会直接退出;当输入其他任何信息时,会依次执行删除和复制操作。
阅读全文