# [SOLVED] Command Line: List files and folders in a directory?



## billybong001 (Feb 14, 2009)

Hi guys,

I need to compile a list of the contents of two external hard disk drives, which is estimated to be about 3000 or so folders. what is the command I should use to make Windows automatically generate a txt?

Item is worth noting that in this directory there are also a mix of different filetypes, what I need are only the names of folders AND files in the root directory.

For examplary purposes, let the drive be called D:\, a folder in the root called \FOLD and a file in the root \BILL.doc.

cheerio,
Bill.


----------



## niemiro (Feb 20, 2010)

*Re: Command Line: List files and folders in a directory?*

Hello Bill!

So you don't want to recurse, or you do?

Will *dir E:\* do the trick, or not, and why? You could then pipe it *dir E:\ > %userprofile%\Desktop\test.txt*

Otherwise, look at OTL: http://www.geekstogo.com/forum/topic/277391-otl-tutorial-how-to-use-oldtimer-listit/

Click the NONE button, paste this in, and click RUN SCAN: 

C:\*.
C:\*.*

If you want recursion, you need to use /FP.

Good luck!

Richard


----------



## jenae (Jun 17, 2008)

*Re: Command Line: List files and folders in a directory?*

Hi, well using your example:-

dir /s /a "D:\Fold\Bill.doc" > c:\find.txt & start notepad c:\find.txt

Output should open in notepad. OR contents of all \Fold

dir /s /a "D:\Fold*.*" > c:\find.txt & start notepad c:\find.txt

*NOTE* If you want the output to go to another drive change the C: to your preferred.


----------



## billybong001 (Feb 14, 2009)

*Re: Command Line: List files and folders in a directory?*

Hi Jenae,

I tried your suggestion, but that seems to only run through every single file in the directory (about a 100k). I also tried



> dir /s /b > list.txt


which created a text file list.txt that was about 10MB large so that's not what I'm looking for.

I'll try explaining again. :sigh:

/Root
.......FolderA
.................SubfolderA
.................SubfolderA
.................SubfolderA
.................SubfolderA
.................SubfolderA
.......FolderB
.................SubfolderB
.................SubfolderB
.................SubfolderB
.................SubfolderB
.................SubfolderB

One more level down and these are all the individual files. I need only a listing of the Folder A's and Folder B's. Is this possible? Not necessary to complete the entire task using a single command prompt; I was thinking one for FolderA and FolderB etc. It's the subfolders where I really need the automation.

Thanks again for your patience and assistance.

Cheerio,
Nicholas.


----------



## jenae (Jun 17, 2008)

*Re: Command Line: List files and folders in a directory?*

Hi, these are your options:-

Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Windows\system32>dir /?
Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/R Display alternate data streams of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4  Displays four-digit years

Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.


----------



## billybong001 (Feb 14, 2009)

*Re: Command Line: List files and folders in a directory?*

Hi Jenae,

Your post was most helpful and solved my problem. Thanks alot. :grin:

Cheerio,
Bill.


----------



## jcgriff2 (Sep 30, 2007)

*Re: Command Line: List files and folders in a directory?*

I like the TREE command myself -

```
[FONT=Lucida Console]tree c:\ /a > 0 & start notepad 0[/FONT]
```
For folders and files -

```
[FONT=Lucida Console]tree c:\ /a /f > 0 & start notepad 0[/FONT]
```
Regards. . .

jcgriff2

`


----------

