Try this:
@echo off
Set FOLDER=Shared_Location_path
Set DEST=%FOLDER%\folders.txt
:repeat
FOR /F %%i IN ('dir %FOLDER% /b /ad-h /o-d') DO (
SET LS=%%i
GOTO :found
)
@echo No more subfolders found
goto :finish
:found
echo Most recent subfolder: %LS%
SET FOLDER=%FOLDER%\%LS%
echo %FOLDER% >> %DEST%
goto :repeat
:finish
@echo File: "%DEST%" created.
It's a bit basic, but it should help to drill down through the direcdtories. You could also make the search into a separate batch file and use the
CALL
command to execute it.
Modified per OP's request.