Not really sure what you're looking for here, but throwing this together was more fun than working:
@echo off
set "dir=C:\Your\Top\Folder"
del /f /q "%dir%\index.txt"
if exist "%dir%" (
echo(
echo Report for:
echo %dir%
echo(
echo Subfolders:
dir /a:d /o:n /b "%dir%"
echo(
echo Files:
dir /a:-d /o:n /b "%dir%"
echo(
echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
)>>"%dir%\index.txt"
for /d /r "%dir%" %%A in (*) do (
echo(
echo Report for:
echo %%A
echo(
echo Subfolders:
dir /a:d /o:n /b "%%A"
echo(
echo Files:
dir /a:-d /o:n /b "%%A"
echo(
echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
)>>"%dir%\index.txt"
Naturally, you can keep/toss/change any part of this to make your output file look the way you want - so this is really just to give you an idea. This sets a dir
variable as your top-folder so we can change things up easier. The if exist
is there just to get the dir
output for that top-folder - otherwise we have a for /d /r
command that will loop recursively through it. The output layout is personal preference based on what I found the most appealing (without worrying about it too much) to look at after looping this through several places. You'll notice after setting the dir
variable the first thing the batch does is delete the index file so I wouldn't have to manually do it after every time I checked it - otherwise >>
will just keep echo'ing multiple runs to the end of it.
If you were wanting a separate index file for each subfolder, all you have to do is enable delayed expansion and nest the main part of the for
loop like this:
setlocal enabledelayedexpansion
for /d /r "%dir%" %%A in (*) do (
set "name=%%~nA"
(echo(
echo Report for:
echo %%A
echo(
echo Subfolders:
dir /a:d /o:n /b "%%A"
echo(
echo Files:
dir /a:-d /o:n /b "%%A"
echo(
echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\)>>"%dir%\!name! index.txt"
)
This will give you a separate text file with the name of the folder (%%~nA
) in the title of each one. If you're lazy like me and want to delete the individualized index files prior to running this the nth number of times, you can throw an if exist "%dir%\!name! index.txt" del /f /q "%dir%\!name! index.txt"
immediately after setting the name
variable in the loop - which I might as well put in a block:
for /d /r "%dir%" %%A in (*) do (
set "name=%%~nA"
if exist "%dir%\!name! index.txt" del /f /q "%dir%\!name! index.txt"
(echo(
Let me know if you were looking for something totally different, or if this was helpful at all.
References: dir and for.