批处理:以txt中的路径和大小递归列出文件

时间:2016-04-05 07:54:21

标签: batch-file recursion

尝试递归列出所有文件,其中只包含路径,名称和文件夹大小,并在txt中输出。 我打算为两个文件夹执行此操作,并比较2输出txt以查看它们是否相同。

现在我试过了:

@echo off for /R "F:\Folder1\MyFolder\" %A in (*.*) do echo %~pnA %~zA > output.txt

但是现在似乎递归在我的情况下不起作用,因为我得到了:

\Folder\MyFolder\MyFile 23617195 

2 个答案:

答案 0 :(得分:0)

尝试附加结果:

for /R "F:\Folder1\MyFolder\" %A in (*.*) do echo %~pnA %~zA >> output.txt

答案 1 :(得分:0)

如果你愿意,你也可以尝试这样的事情:

@echo off 
Set LogFile=Path_Size.txt
if exist %LogFile% Del %LogFile%
Set Folder=c:\test
(
    for /f %%a in ('dir /s /b %Folder%') do (
        echo "%%~fa" & Call:GetSize %%a & echo ******************
        )
)>>%LogFile% 2>nul
Start "" %LogFile%
pause

:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFile^)
echo    Set fso = CreateObject("Scripting.FileSystemObject"^)
echo    Set objFile= fso.GetFile(MyFile^)  
echo    GetSize = FormatSize(objFile.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo    aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo    For i = 0 to 4
echo        If iSize ^> 1024 Then
echo            iSize = iSize / 1024
echo        Else
echo            Exit For
echo        End If
echo    Next
echo    FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b