DIR LIST of Files in EACH SUB Directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RVDLD
Posts: 1
Joined: 11 Aug 2007 08:40

DIR LIST of Files in EACH SUB Directory

#1 Post by RVDLD » 11 Aug 2007 09:32

Filestructure:
C:\test – map
C:\test – map\TEST - A
C:\test – map\TEST - A\A 1 TESTA-A 1.txt
C:\test – map\TEST - A\ A 2 TESTA-A2.txt
C:\test - map\TEST - B
C:\test - map\TEST - B\ B1 TEST - B-B1.txt
C:\test - map\TEST - B\ B–2 TEST - B-B2.txt
C:\test - map\TEST - B\ B2 \ C1 TEST - B-B2-C1.txt
C:\test – map\TEST - B\B2\ C2\file1.txt + file2.txt TEST - B-B2-C2.txt

Wish:
I would like to have a batch file what could make a listing of all the filenames in to one txt file for each directory , sub dir and sub sub dir.
The TXT should be located in the directory which files it is listing.
Filename of TXT.File should be a combination of the subsequent directories.
For example: TEST – B-B2-C2.txt
Content of TXT File: TEST – B-B2-C2.txt
File1.txt
File2.txt
Well, any help would be appreciated.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 12 Aug 2007 01:02

RVDLD,

How about this:

Code: Select all

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set "StartDir=%userprofile%\"

for /f "delims=" %%A in ('dir /s /b /ad "%StartDir%"') do (
   set "OutputFile=\\%%A"
   set "OutputFile=!OutputFile:\\%StartDir%=!"
   set "OutputFile=!OutputFile:\=-!
   dir /b /a-d "%%A" > "__!OutputFile!.txt" 2>NUL
)
pause

DOS IT HELP?

Post Reply