@echo off
fsutil >nul 2>nul
if "%errorlevel%"=="1" echo 非管理员身份运行&ping/n 5 127.1>nul&exit
if "%errorlevel%"=="9009" echo 运行环境必须是 Windows XP Professional 以上系统&ping/n 5 127.1>nul&exit
for /f "skip=2 tokens=2,3 delims=," %%i in ('WMIC LogicalDisk Where "DriveType=2 and SupportsDiskQuotas=FALSE" Get DeviceID^,FreeSpace /format:csv 2^>nul') do call :xxx %%i %%j
if not defined freesize echo 未找到可移动磁盘
pause&exit
:xxx
set freesize=%2
if not defined freesize goto:eof
if exist "%1\test.txt" del /q "%1\test.txt"
echo 正在写入%freesize%字节大小的测试文件到%~1盘...
fsutil file createnew "%1\test.txt" %freesize% >nul&&echo %1 盘文件拷贝测试成功!||echo %1 盘文件拷贝测试失败
del "%1\test.txt" 2>nul
echo.
goto:eof
rem 獲取磁盤容量
@echo off
for /f "skip=1 delims= " %%a in ('"Wmic LogicalDisk Where DriveType="2" Get DeviceID|find /v "N:""') do call :xxx "%%a"
pause
:xxx
if "%~1"=="" goto:eof
if exist "%~1\test.txt" del /q "%~1\test.txt"
for /f "tokens=3" %%b in ('dir/-c "%~1\"^|find "可用字節"') do set freesize=%%b
echo 正在寫入%freesize%字節大小的測試文件到%~1盤...
fsutil file createnew "%~1\test.txt" %freesize% >nul&&echo %~1 盤文件拷貝測試成功!||echo 盤文件拷貝測試失敗
del "%~1\test.txt" 2>nul
echo.
goto:eof
@echo off
for /f "skip=1 delims= " %%a in ('"Wmic LogicalDisk Where DriveType="2" Get DeviceID|find /v "A:""') do call :xxx "%%a"
pause
:xxx
if "%~1"=="" goto:eof
if exist "%~1\test.txt" del /q "%~1\test.txt"
for /f "tokens=3" %%b in ('dir/-c "%~1\"^|find "位元組可用"') do set freesize=%%b
echo 正在写入%freesize%字节大小的测试文件到%~1盘...
fsutil file createnew "%~1\test.txt" %freesize% >nul&&echo %~1 盘文件拷贝测试成功!||echo 盘文件拷贝测试失败
del "%~1\test.txt" 2>nul
echo.
goto:eof