|
Answer» Hi,
I am quite new to the Dos yet, would need a solution on the below. OS MS XP Professional Writing on DOS in batch .BAT file
Would need to perform a count and list inside a text file:
Inside Data.txt file:
C:\Test\T1\C1\File1.txt C:\Test\T1\C2\File1.txt C:\Test\T1\C2\File2.txt
C:\Test\T2\C2\File1.txt C:\Test\T2\C2\File1.txt
C:\Test\T3\C1\File1.txt C:\Test\T4\C1\File1.txt C:\Test\T5\C1\File1.txt
Wish to have the below output screen:
Output to screen: Folder T1\C1\ 1 File(s) Folder T1\C2\ 2 File(s) Folder T2\C2\ 2 File(s) Folder T3\C1\ 1 File(s) Folder T4\C1\ 1 File(s) Folder T5\C1\ 1 File(s)
I manage to create the Data.txt file using a for loop to list all files in folder and sub folder. But i need to generate a statistics summary for each folder.
Hope all the Gurus can help. Appreciate your help in advance.
Simon Finally have manage what i want. Maybe you have a better solution.
REM Compile the folder STATISTICS. CLS Echo Folder Statistics: Echo. SET /A Count1=0 For /F "Delims=" %%i IN ('Dir /B /AD "%CD%\%CF%\"') DO ( For /F "Delims=" %%j IN ('Dir /B /AD "%CD%\%CF%\%%i"') DO ( If !Count1! GTR 0 Echo Folder [!p!] Contains !Count1! Files. Set /A Total=Total+Count1 Set /A Count1=0 For /F "Delims=" %%y IN ('Dir /B /A-H "%CD%\%CF%\%%i\%%j\" ".bmp"') DO ( Set /A Count1=Count1+1 Set p=%%i\%%j ) ) ) Echo Folder [%p%] Contains %Count1% files. Set /A Total=%Total%+%Count1%"Maybe you have a better solution. "
Why mess with something that works?
Couple of questions though, where did %CF% get it's value from? and is not the p variable being used before it's value is set?
Just asking. Yup, i think i miss to set the p variables.
For the CF is actually a variable for folder selection in the earlier stage, apologies for not showing... coz dun wanna mess up the question with plenty of unnecessary codes...
@echo off Title File Lister Setlocal Enabledelayedexpansion
REM Generate FILE NAME :START CLS Set /P Name=Enter a file title :
Set HR=%time:~0,2% if %HR% LSS 10 set hour=0%hour:~-1% CLS Echo Generating file list... Set Filename=%Name% %date:~-4%%date:~-10,2%%date:~-7,2%.csv
REM Search for EXISTING FILES List If Exist "%Filename%" ( Goto SLT ) ELSE ( Goto GEN ) Goto END
REM CHOICE and Selection : SLT Echo The file is currently exist in directory, Echo [1] To replace the file entirely with new data. Echo [2] To continue writing new data under same file. Echo [3] To choose a new file title. Set /P Choice=Enter a choice : ) If "%Choice%" EQU "3" Goto START If "%Choice%" EQU "2" Goto GEN If "%Choice%" EQU "1" Echo. > "%Filename%" Goto GEN
REM Prompt User to CHOOSE a FOLDER to output list: :GEN CLS Echo Type a main folder below to list output: Echo Enter 0 if default folder [DefaultFolder] is used. Echo. For /F "Delims=" %%i IN ('Dir /B /AD "%CD%\"') DO ( Echo %%i ) Echo.
Set /P CF=Folder Name : If "%CF%"=="0" Set CF=Atlanta Defects Echo Folder named [%CF%] is choosen.
REM Begin to LIST ALL FILES from current and sub directories.
For /F "Delims=" %%i IN ('Dir /B /AD "%CD%\%CF%\"') DO ( For /F "Delims=" %%j IN ('Dir /B /AD "%CD%\%CF%\%%i"') DO ( Echo.
Echo [%%i] Folder Contains: For /F "Delims=" %%y IN ('Dir /B /A-H "%CD%\%CF%\%%i\%%j\" ".bmp"') DO ( Echo %%i\%%j\%%y Echo %%i\%%j\%%y >> "%Filename%" ) ) )
REM Compile the folder STATISTICS. CLS Echo Folder Statistics: Echo. Set /A Count1=0 For /F "Delims=" %%i IN ('Dir /B /AD "%CD%\%CF%\"') DO ( For /F "Delims=" %%j IN ('Dir /B /AD "%CD%\%CF%\%%i"') DO ( If !Count1! GTR 0 Echo Folder [!p!] Contains !Count1! Files. Set /A Total=Total+Count1 Set /A Count1=0 For /F "Delims=" %%y IN ('Dir /B /A-H "%CD%\%CF%\%%i\%%j\" ".bmp"') DO ( Set /A Count1=Count1+1 Set p=%%i\%%j ) ) ) Echo Folder [%p%] Contains %Count1% files. Set /A Total=%Total%+%Count1% Echo. Echo Total All Listed Files %Total%
Echo Document listed on %Date% %Time% Echo Document listed on %Date% %Time% >> "%Filename%" Echo Refer to %CD%\%Filename% for generated file list. Echo.>>"%Filename%" Echo.
Pause
|