Board logo

标题: 批处理遍历文件夹大小代码如何修改? [打印本页]

作者: bd123456789     时间: 2010-7-26 12:53    标题: 批处理遍历文件夹大小代码如何修改?

@echo off
for /f "tokens=*" %%b in ('dir') do echo "%%b"|find "个文件">nul&&for /f "tokens=3*" %%c in ("%%b") do echo 当前目录 %%c %%d
for /f %%a in ('dir/ad/s/b') do for /f "tokens=*" %%b in ('"dir %%a\"') do echo "%%b"|find "个文件">nul&&for /f "tokens=3*" %%c in ("%%b") do echo %%a %%c %%d
pause

要达到目的
一\对有空格的文件夹也能正常遍历
二\对字节数能否改为MB或G?
三\只需要对当前目录进行遍历..

[ Last edited by bd123456789 on 2010-7-26 at 12:56 ]
作者: lovelymorning     时间: 2010-7-26 15:11

@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('dir /ad /b /s') do (
for /f "tokens=3" %%b in ('dir "%%a"^|find "个文件"') do (
set s=%%b
set s=!s:,=!
echo 当前目录%%a大小为:!s! 字节
echo.
set /a s=s/1024
echo 当前录%%a大小为:!s! M
)
)
pause
自己参考一下。。。。
作者: bd123456789     时间: 2010-7-27 11:42    标题: 谢了

@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('dir /ad /b') do (
for /f "tokens=3" %%b in ('dir "%%a"^|find "个文件"') do (
set s=%%b
set s=!s:,=!
echo 当前目录%%a大小为:!s! 字节
echo.
set /a s=s/1024/1024
echo 目录→%%a---------------------------    !s! M>>当前目录占用空间.txt
)
)
pause

OK,这是我修改好的