Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of sub-folders and their files, ordered by folder-names

Can I use dir command-line to get a list of sub-folders and their files, ordered by folder-names, and not just file-names ?

using

dir /s/b/o:gn > f.txt

I first get all sub-folders and only then all sub files, e.g.:

 d:\root0\root1\folderA  d:\root0\root1\folderB  d:\root0\root1\file00.txt  d:\root0\root1\file01.txt  d:\root0\root1\folderA\fileA00.txt  d:\root0\root1\folderA\fileA01.txt  d:\root0\root1\folderB\fileB00.txt  d:\root0\root1\folderB\fileB01.txt 

But I want to get -

d:\root0\root1\file00.txt d:\root0\root1\file01.txt d:\root0\root1\folderA d:\root0\root1\folderA\fileA00.txt d:\root0\root1\folderA\fileA01.txt d:\root0\root1\folderB d:\root0\root1\folderB\fileB00.txt d:\root0\root1\folderB\fileB01.txt 

["file00.txt" and "file01.txt" can also be at the end of the list]

Thanks,

Atara

like image 855
Atara Avatar asked Aug 10 '10 09:08

Atara


People also ask

How can I get a list of all the subfolders and files present in a directory using PHP?

PHP using scandir() to find folders in a directory The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.

How do you create a text file list of the contents of a folder and subfolders?

In the DOS command prompt, navigate (by using "cd C:foldernamefoldername etc until you are there) to the level that contains the folder in question (do not navigate *into that folder); then type the name of the folder for whose contents you want to generate a file list, followed by a ">", then enter a name for the file ...

How do you get a list of all files in a folder and subfolders command prompt?

You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.


2 Answers

How about using sort?

dir /b /s | sort 

Here's an example I tested with:


dir /s /b /o:gn

d:\root0 d:\root0\root1 d:\root0\root1\folderA d:\root0\root1\folderB d:\root0\root1\file00.txt d:\root0\root1\file01.txt d:\root0\root1\folderA\fileA00.txt d:\root0\root1\folderA\fileA01.txt d:\root0\root1\folderB\fileB00.txt d:\root0\root1\folderB\fileB01.txt 

dir /s /b | sort

d:\root0 d:\root0\root1 d:\root0\root1\file00.txt d:\root0\root1\file01.txt d:\root0\root1\folderA d:\root0\root1\folderA\fileA00.txt d:\root0\root1\folderA\fileA01.txt d:\root0\root1\folderB d:\root0\root1\folderB\fileB00.txt d:\root0\root1\folderB\fileB01.txt 

To just get directories, use the /A:D parameter:

dir /a:d /s /b | sort 
like image 124
Cylindric Avatar answered Sep 29 '22 04:09

Cylindric


Hej man, why are you using this ?

dir /s/b/o:gn > f.txt (wrong one)

Don't you know what is that 'g' in '/o' ??

Check this out: http://www.computerhope.com/dirhlp.htm or dir /? for dir help

You should be using this instead:

dir /s/b/o:n > f.txt (right one)

like image 33
appsomobile Avatar answered Sep 29 '22 03:09

appsomobile