Directory tree

How can I get a directory listing of directories and sub-directories using a batch file but I want to exclude the directory name. I've tried the following 

dir /s/b/o:n/a:d > Listings.txt 

but I seem to still get the directory path included

August 27th, 2015 6:56pm

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 8:04pm

How can I get a directory listing of directories and sub-directories using a batch file but I want to exclude the directory name. I've tried the following 

dir /s/b/o:n/a:d > Listings.txt 

but I seem to still get the directory path included


Your question is unclear. Please clarify it with an example.
August 27th, 2015 8:05pm

I want the following 

original

C:\Users\%username%\Desktop\Scripts\acctinfo.dll

C:\Users\%username%\Desktop\Scripts\Alockout.zip

C:\Users\%username%\Desktop\Scripts\AlockoutXP.zip

What i'm looking for all parent and child folder listing. It is only doing parent folder

acctinfo.dll
Alockout.zip
AlockoutXP.zip



  • Edited by eorosz3 Thursday, August 27, 2015 8:42 PM
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 8:42pm

I want the following 

original

C:\Users\%username%\Desktop\Scripts\acctinfo.dll

C:\Users\%username%\Desktop\Scripts\Alockout.zip

C:\Users\%username%\Desktop\Scripts\AlockoutXP.zip

What i'm looking for all parent and child folder listing. It is only doing parent folder

acctinfo.dll
Alockout.zip
AlockoutXP.zip



  • Edited by eorosz3 Thursday, August 27, 2015 8:42 PM
August 27th, 2015 8:42pm

In your first example it looks like you were looking for all entries that were directories.  So I assume you want the list of directory names sorted by name ascending, without the full path.  Is this what you're looking for?

powershell "gci * -recurse | sort-object Name | ?{$_.Attributes -eq 'Directory'} | %{$_.Name}"

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 8:57pm

Yes but It needs to be in a batch file that I can give to users on a domain to pull a directory list of subdirectories plus the file names in the folders. 
August 27th, 2015 9:26pm

Your question is still vague.

Type out a list of directories, and then give an example of output you're expecting. Also tell what you have tried so far.

So far you're making everyone guess at what you are doing and what is not working. We can't see your screen.

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 10:01pm

Here is my code in the .bat file. I copy the .bat into the share drive with all nested folders, I run the batch it outputs the text file with everything that is root of the share.

dir /s/b/o:n > Listing.txt

H:\.swfinfo
H:\contacts.csv
H:\directory listing - All Files.bat
H:\Eric's Desktop\Change to file ext. wsf NTUser.wsf
H:\Eric's Desktop\Clearing the Clipboard Cache.bat.lnkH:\Eric's Desktop\Important Work Related Stuff!!!!!\Adding & Removing Email From an iPad or iPhone.DOC
H:\Eric's Desktop\Important Work Related Stuff!!!!!\AdobeZip fix.reg

H:\Info\BigHand\Notes\Android\Dication and sending\Screenshot_2015-03-02-13-23-19.png

H:\Info\BigHand\Notes\Android\Dication and sending\Screenshot_2015-03-02-13-23-30.png

My end result is to eliminate the directory path from the subdirectories and only list the actual file names. 


  • Edited by eorosz3 17 hours 38 minutes ago
August 28th, 2015 9:31am

My end result is to eliminate the directory path from the subdirectories and only list the actual file names.

What's the purpose of doing that? If a file is in a subdirectory, how will you know where to find it?

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 10:27am

I had a user that just wanted to get a list of all file names in folders so he can paste the data in a word document. 
August 28th, 2015 10:56am

I still don't see the purpose if you don't have the path of the file. You will have to manually search a subdirectory tree every time. Also there can be duplicates in such a list - how do you know which file?

Here's how you would get a list of filenames only using PowerShell:

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 11:02am

My end result is to eliminate the directory path from the subdirectories and only list the actual file names. 

I can't quite see the point of doing something like this. Anyway, here is a batch file method:

@echo off
for /F "delims=" %%a in ('dir H:\  /s  /b  /ad') do dir "%%a" /b /a-d 2>nul

August 28th, 2015 11:19am

Will that output to a txt file in the same location?
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 11:49am

Start here:

https://technet.microsoft.com/en-us/scriptcenter/dd772284.aspx

August 28th, 2015 12:51pm

Here is my code in the .bat file. I copy the .bat into the share drive with all nested folders, I run the batch it outputs the text file with everything that is root of the share.

dir /s/b/o:n > Listing.txt

H:\.swfinfo
H:\contacts.csv
H:\directory listing - All Files.bat
H:\Eric's Desktop\Change to file ext. wsf NTUser.wsf
H:\Eric's Desktop\Clearing the Clipboard Cache.bat.lnkH:\Eric's Desktop\Important Work Related Stuff!!!!!\Adding & Removing Email From an iPad or iPhone.DOC
H:\Eric's Desktop\Important Work Related Stuff!!!!!\AdobeZip fix.reg

H:\Info\BigHand\Notes\Android\Dication and sending\Screenshot_2015-03-02-13-23-19.png

H:\Info\BigHand\Notes\Android\Dication and sending\Screenshot_2015-03-02-13-23-30.png

My end result is to eliminate the directory path from the subdirectories and only list the actual file names. 


  • Edited by eorosz3 Friday, August 28, 2015 1:32 PM
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 1:28pm

Will that output to a txt file in the same location?

We do not which reply your question relates to . . .

@echo off
if exist H:\Files.log del H:\Files.log
for /F "delims=" %%a in ('dir H:\  /s  /b  /ad') do dir "%%a" /b /a-d 1>> H:\Files.log  2>nul

August 28th, 2015 4:38pm

Will that output to a txt file in the same location?

We do not which reply your question relates to . . .

@echo off
if exist H:\Files.log del H:\Files.log
for /F "delims=" %%a in ('dir H:\  /s  /b  /ad') do dir "%%a" /b /a-d 1>> H:\Files.log  2>nul

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 8:36pm

Will that output to a txt file in the same location?

We do not which reply your question relates to . . .

@echo off
if exist H:\Files.log del H:\Files.log
for /F "delims=" %%a in ('dir H:\  /s  /b  /ad') do dir "%%a" /b /a-d 1>> H:\Files.log  2>nul

  • Proposed as answer by Frederik Long Saturday, August 29, 2015 8:40 PM
August 28th, 2015 8:36pm

Will that output to a txt file in the same location?

We do not which reply your question relates to . . .

@echo off
if exist H:\Files.log del H:\Files.log
for /F "delims=" %%a in ('dir H:\  /s  /b  /ad') do dir "%%a" /b /a-d 1>> H:\Files.log  2>nul

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 8:36pm

will I be able to narrow down a dir location from this line  ('dir H:\  /s  /b  /ad') let say a specific folder instead of doing the entire root of the directory? 

How do you account for a folder with spaces and characters in the name like (' - etc

  • Edited by eorosz3 Thursday, September 03, 2015 7:04 PM
September 3rd, 2015 6:59pm

You are not clarifying anything by continuing to ask impenetrably vague questions. You need to start over and ask a clear question. The following resources will help you to ask a coherent question:
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 7:10pm

Okay i'm sorry, lets say I want grab the file listing names for one or two of the folders in a directory but they have spaces or special character for example (Eric's Desktop or characters like the !!!!!, &, *) using that previous command below. Is there a way to include certain delimiters like the Tab, Space

@echo off
if exist H:\listing.log del H:\listing.log
for /F "delims=" %%a in ('dir C:\ /s  /b  /ad') do dir "%%a" /b /a-d 1>> H:\listing.log 2>nul

September 3rd, 2015 7:26pm

Yes. Place " characters (quotes) around the parameter to the dir command; e.g.:

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 7:36pm

Yes. Place " characters (quotes) around the parameter to the dir command; e.g.:

September 3rd, 2015 10:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics