我正在创建一个批处理文件,它将根据来自外部文本文件的数组中的路径收集信息(大小、文件数和文件夹数)。目前,我可以获得这些详细信息,但我只获得文本文件中列出的最后一条路径的信息。
这是我到目前为止所做的:
::Title for the cmd window
TITLE Getting Repository information
ECHO OFF
::Setting parameters
setlocal ENABLEDELAYEDEXPANSION
set today=!date:/=-!
::Setting the location of the output file
set output=!C:\Users\%username%\Desktop\output_!today!.txt!
set pathway=!C:\Users\%username%\Desktop\pathways.txt!
ECHO ------------------------------------------------------------>> !output!
ECHO ----------Time to get some repository information:---------->> !output!
ECHO ------------------------------------------------------------>> !output!
ECHO.>> !output!
ECHO %date% %time%>> !output!
ECHO.>> !output!
ECHO.>> !output!
::Creating an array
setlocal EnableDelayedExpansion
set i=0
for /F %%a in (C:\Users\%username%\Desktop\pathways.txt) do (
set /A i+=1
set array[!i!]=%%a
)
set n=%i%
for /L %%i in (1,1,%n%) do (set folder=!array[%%i]!)
::Getting the repository size (only displays the size info for the location of this file)
ECHO OFF
Set _size=0
For /F "tokens=3 delims= " %%I In ('Dir %folder% /a-d /S ^|Find /I "file(s)"') Do Set _size=%%I
ECHO %folder% %_size% Bytes>> !output!
::Getting the number of folders
for /f %%a in ('dir /b /s /ad %folder%^|find /c /v "" ') do set count=%%a
ECHO %folder% %count% folder(s^)>> !output!
::Getting the number of files
set /a count=0
for /f "tokens=* delims= " %%a in ('dir/s/b/a-d %folder%') do (
set /a count+=1
)
ECHO %folder% %count% file(s)>> !output!
ECHO ============================================================>> !output!
ECHO ============================================================>> !output!
ECHO.>> !output!
很抱歉弄得乱七八糟。我不能很好地缩进它。我可能忽略了一些东西。任何帮助表示赞赏。
谢谢!