我知道这可能是愚蠢的事情,而且我不是一个专家批处理程序员,但我遇到了一个小问题。
我从备份脚本中删除了备份功能(效果非常好),并尝试将其作为格式化脚本。代码包括:
@echo off
title CrucialBlue Simple Format Utility
echo Drives will be formatted, and all data will be lost! Please ensure the drive letter you chose is correct before continuing
echo Retrieving list of disk locations...
wmic logicaldisk get caption,volumename,providername
echo.
set /p drive=Enter only the drive letter of the drive you're attempting to format:
set /p form=Enter a file system to use (NTFS/FAT/FAT32):
echo.
IF EXIST %drive% format %drive%: /q fs:%form%
IF NOT EXIST %drive% echo Your drive was not formated because the drive you entered does not exist.
echo.
echo Program completed. Press any key...
pause > nul
我认为问题在于我的IF EXIST语句,其中实际函数调用这两个变量......任何人都有任何想法?
答案 0 :(得分:1)
更改
IF EXIST %drive% format %drive%: /q fs:%form%
到
IF EXIST %drive%: format %drive%: /q fs:%form%
(请注意第一个:
之后添加的%drive%
)
答案 1 :(得分:0)
如果您使用批处理中的内置关联数组,则可以实现它:
@ECHO OFF &SETLOCAL
title CrucialBlue Simple Format Utility
echo Drives will be formatted, and all data will be lost! Please ensure the drive letter you chose is correct before continuing
echo Retrieving list of disk locations...
for /f %%a in ('wmic logicaldisk get caption') do set "$%%a=1"
wmic logicaldisk get caption,volumename,providername
echo.
set /p "drive=Enter only the drive letter of the drive you're attempting to format: "
set /p "form=Enter a file system to use (NTFS/FAT/FAT32): "
echo(
IF DEFINED $%drive%: (
ECHO format %drive%: /q fs:%form%
) ELSE (
echo Your drive was not formatted because the drive you entered does not exist.
)
echo(
查看输出,如果看起来不错,请删除ECHO
。