2

I need a list of all the files and folders in a folder. My end goal is to print out this list on paper. I don't want this to be recursive, so I don't need a list of the files in folders and the folder being searched. So for example there's folder name foo and it contains the files bar and wombat and a folder called crazy so I need the list to contain

  • bar
  • wombat
  • crazy

I'm using Windows 7.

1

3 Answers 3

7

Well, from the Windows shell, you can direct the output of dir to a file like this:

dir > list.txt

which will give you the full directory listing. And if you use the /b option, dir will just output the file and directory names, without the additional information:

dir /b > list2.txt
2
  • Thanks, does this get hidden files and folders?
    – Celeritas
    Jun 21, 2013 at 20:45
  • 1
    No. You need to use the /a:- option for a listing that includes hidden files and folders. Use dir /? to see a list of options.
    – Mox
    Jun 21, 2013 at 20:51
1

You could also use Powershell:

Get-ChildItem -Force 

Would get all items, including hidden and protected.

You can the use PowerShell commands to format the text however you wish:

Get-ChildItem -Force | Select-Object Name, Attributes, Extension, LastAccessTime
| Out-File "C:\Results.txt"

Which would look something like:

enter image description here

4
  • @AthomSfere ls -Fo short form Get-ChildItem -Force ...
    – STTR
    Jun 21, 2013 at 22:39
  • 1
    @STTR yes, gci can also be used for Get-ChildItem, ls is the linux equivalent of dir too. I always use longform in scripts though for easy readability for me, new users and posterity. Jun 21, 2013 at 22:49
  • @AthomSfere It seems to me that a simple, though not the right approach will win). And our perversions with powershell not wanted, that's sad. As a gift analogue paste-d: powershell $f1=gc col1.txt;$f2=gc col2.txt;for($i=0;$i-lt$f1.length;++$i){$f1[$i]+$f2[$i]}>col-new1-2.txt
    – STTR
    Jun 21, 2013 at 23:04
  • Don't force it. Mar 12, 2019 at 12:05
1

/B - Uses bare format (no heading information or summary)

/A:- - displays files and folders with any attributes

/O:G-N - sort G - Group directories first, -N - reverse By name (alphabetic)

dir /B /A:- /O:G-N

Output:

bar
wombat
crazy

@Mox answer command:

dir /b

Output:

bar
crazy
wombat

@Mox answer command, if wombat set hidden attribute:

dir /b

Output:

bar
crazy

sample at foo folder and save output to C:\mushroom.txt

dir /B 'C:\foo' /A:- /O:G-N>C:\mushroom.txt

powershell alternative:

powershell ls -Fo^|sort Mode,Name -desc^|ft Name -Au -Hi

powershell alternative, file save:

powershell ls -Fo^|sort Mode,Name -desc^|ft Name -Au -Hi|more /E +1>C:\mushroom.txt
2

Not the answer you're looking for? Browse other questions tagged .