Page 1 of 1

Log directory structure to output file Batch file (.bat)

Posted: Sun Mar 01, 2015 10:55 pm
by dzcadii
Simple way to iterate through a directory structure and log the output.
  1. Files only
  2. Directories only
  3. Directories and files
*Note: Place this file in the root of where you want the scanning to begin
Deliminator is "::.::"
Save file as yourfilename.bat (just make sure the extension is ".bat"

Code: Select all

@echo off
setLocal EnableDelayedExpansion

set hr=%TIME: =0%
set hr=%hr:~0,2%
::echo %hr%

set min=%TIME:~3,2%
::echo %min%

set sec=%TIME:~6,2%
::echo %sec%

set log_file=%date:~10,4%%date:~4,2%%date:~7,2%_%hr%%min%%sec%_scan_results.txt

set /P RESULT=[Please select an option(1-Files/2-Directories/3-All)]

IF %RESULT% == 1 GOTO Option1
IF %RESULT% == 2 GOTO Option2
IF %RESULT% == 3 GOTO Option3

echo "I am logging all files ONLY"
for /r %%a in (*) do echo %%a::.::%%~za >> %log_file%
goto DONE

echo "I am logging all directories ONLY"
for /d %%a in (*) do dir /ad /on /s /b "%%a" >> %log_file%
goto DONE

echo "I am logging all directories and files"
for /d %%a in (*) do dir /ad /on /s /b "%%a" >> %log_file%
for /r %%a in (*) do echo %%a::.::%%~za >> %log_file%
goto DONE

echo I have written the results to %log_file%