Page 1 of 1

list all folders and subfolders to an list.txt file

Posted: 28 May 2014 01:36
by imagination
Good morning all,

I am having an question
I need an batch script that does the following thing.

it needs to loop true an root directory and then put all its folders and their subfolders into an file.
Only it needs to be in an specific format.

I will show you the code that i already have for the files.

Code: Select all

setlocal EnableDelayedExpansion
echo Ver:24 >%PATCHER_FOLDER%\list.txt
echo  C:\\RESCLIENT>>%PATCHER_FOLDER%\list.txt
echo. >>%PATCHER_FOLDER%\list.txt
set "base=%CD%"
set "base=%base:*:=%\"

for /R %%a in (*.*) do (
   for /F "tokens=1-5 delims=/-. " %%b in ("%%~Ta") do set "dateTime=%%b-%%c-%%d  %%e%%f"
   set "size=                   %%~Za"
   set name= %%~PNXa
   echo !dateTime! !size:~-19! !name:%base%=!>>%PATCHER_FOLDER%\list.txt
)

echo List.txt has been created inside the following Directory(%PATCHER_FOLDER%)
pause
GOTO MANAGE_PATCHER


This will produce an list.txt like this

Code: Select all

Ver:24 
 C:\\RESCLIENT
 
2014-05-27  09:37            29293018  Pandora_00.res
2014-05-11  15:41            19287692  Char\Pandora_00.res


As you can see its in an specific format.
Now i whant it to look like this

Code: Select all

Ver:24 
 C:\\RESCLIENT
 
2014-05-27  09:37            29293018  Pandora_00.res
2014-05-27  15:41      <DIR>           Char
2014-05-11  15:41            19287692  Char\Pandora_00.res


If you can help me with this i will appreciate it.

With kind regards,

Thomas de vries.

Re: list all folders and subfolders to an list.txt file

Posted: 31 May 2014 21:00
by Yury

Code: Select all

setlocal enabledelayedexpansion
echo Ver:24 >%PATCHER_FOLDER%\list.txt
(
echo  C:\\RESCLIENT
echo.
@for /f "tokens=1-5* delims=/-. " %%i in ('
 dir /o-g /s^| findstr /bvc:" "^| findstr /ev \.
') do @(
 if not "%%m"=="<DIR>" (
  set size=                   %%m
  set size=!size:~-20!
  if not defined dir (
   echo %%k-%%j-%%i  %%l!size!  %%n
   ) else (
   echo %%k-%%j-%%i  %%l!size!  !dir!\%%n
   )
  ) else (
  set dir=%%n
  echo %%k-%%j-%%i  %%l      ^<DIR^>           %%n
  )
 )
)>>%PATCHER_FOLDER%\list.txt
echo List.txt has been created inside the following Directory(%PATCHER_FOLDER%)
pause
GOTO MANAGE_PATCHER

Re: list all folders and subfolders to an list.txt file

Posted: 01 Jun 2014 01:25
by Yury
More correctly:

Code: Select all

setlocal enabledelayedexpansion
echo Ver:24 >%PATCHER_FOLDER%\list.txt
(
echo  C:\\RESCLIENT
echo.
@for /f "tokens=1-5* delims=/-. " %%i in ('
 dir /o-g /s^| findstr /bvc:" "^| findstr /ev \.
') do @(
 if not "%%m"=="<DIR>" (
  set size=                   %%m
  set size=!size:~-20!
  if not defined dir (
   echo %%k-%%j-%%i  %%l!size!  %%n
   ) else (
   echo %%k-%%j-%%i  %%l!size!  !dir!\%%n
   )
  ) else (
  if not defined dir (
   echo %%k-%%j-%%i  %%l      ^<DIR^>           %%n
   set dir=%%n
   ) else (
   set dir=!dir!\%%n
   echo %%k-%%j-%%i  %%l      ^<DIR^>           !dir!
   )
  )
 )
)>>%PATCHER_FOLDER%\list.txt
echo List.txt has been created inside the following Directory(%PATCHER_FOLDER%)
pause
GOTO MANAGE_PATCHER


.