-3

我编写了一个批处理文件来从提供的目录列表中获取磁盘空间。将字节转换为 KB 或 MB 时,不会打印任何数据。

@echo OFF
REM SQL CALL TO GET THE DIRECTORY LISTING
FOR /F "tokens=*" %%i in (directoryList.txt) DO (
    for /F "tokens=3" %%S in ('dir %%i ^| findstr /c:"File(s)"') do (
        SETLOCAL
        SET /A "sizeKB=%%S/1024"
        SET /A "sizeMB=%sizeKB% / 1024"
        ECHO "Directory :: %%i with size :: %%S "
        ECHO "IN MEGABYTE :: %sizeMB%"
        ENDLOCAL
        PAUSE
    )
)

上述脚本的输出是...

Directory :: D:\xxx with size :: 723,234,123
IN MEGABYTE :: 

请更正上面的代码。

4

2 回答 2

0
@echo OFF
REM SQL CALL TO GET THE DIRECTORY LISTING
FOR /F "tokens=*" %%i in (directoryList.txt) DO (
    for /F "tokens=3" %%S in ('dir /-c "%%i" ^| findstr /c:"File(s)"') do (
        SETLOCAL ENABLEDELAYEDEXPANSION
        SET /A "sizeKB=%%S/1024"
        SET /A "sizeMB=!sizeKB! / 1024"
        ECHO "Directory :: %%i with size :: %%S "
        ECHO "IN KBYTE :: !sizeKB!"
        ECHO "IN MEGABYTE :: !sizeMB!"
        ENDLOCAL
        PAUSE
    )
)
于 2013-07-26T00:06:50.117 回答
0

您正在获取文本723,234,123,它没有转换为数字,因为,

然后在算法之前删除:

SET "sizeB=%%c"
SET "sizeB=!sizeB:,=!"
SET /A "sizeKB=!sizeB!/1024"
...
于 2013-07-26T10:00:23.990 回答