Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

is there a way to copy list of all folders sub folders 10.8.2

Pretty much as the title says :


I was wondering if there was a way to copy a list of all the names of folders sub folders 10.8.2

into a text file / text files ?


I know I can select folders and files and command+c then paste them into a text file,

but this only works on the contents a single folder .

I want to be able to export as a text file the list of all folders and subfolders within, as I said.


It will be a very long text file, but I would "need" this feature.

Would help me enormously.


Thanks.

MacBook Pro (15-inch Late 2011), OS X Mountain Lion (10.8)

Posted on Dec 8, 2012 6:21 PM

Reply
Question marked as Best reply

Posted on Dec 8, 2012 6:36 PM

Are you game for learning a little Unix and knowing your Mac a little deeper? If you are, do know that OS X is Unix under the pretty graphics and regular Unix commands work just fine in Terminal.


So look up Terminal in Utilities and start it. A blank window will open and the command line prompt will await you at the bottom. First, try out the following Unix command to see if the results are what you want (type the following exactly, then press Enter/Return):


ls -R


If it is good, you will have to navigate to the topmost directory you want the list from. The -R (Recurse) option takes care of recursing down the tree. Use the cd command to change from the default (your home folder) to wherever you need to go. In Unix you separate directories with the / For example, the Utilities folder is in /Applications/Utilities and you can navigate to it by typing:


cd /Applications/Utilities


Can determine the names of all intervening folders by opening a Finder window to the desired place and Command-clicking on its name.


Holler if you need more help.

20 replies

Dec 19, 2012 2:55 AM in response to Topher Kessler

YES! I think I have finally got this, thanks especially to Courcoul and Topher!

Topher, a command in that CNET article you quoted seems to have done the trick!

The process "I" arrived at [or you guys wisely-advised me towards] to list JUST directories and subdirectories [folders and subfolders] and not individual files is this ;

[the following is for anyone else with the same question]

1. Open terminal

type "cd" [means change directory] and then space, drag and drop the directory you want to output the tree / file structure from, from finder into terminal. Enter.

This changes the base directory in terminal

so if you want the folders and subfolders from music folder,

you type "cd " [with a space before and after] then drag and drop music folder from finder into terminal.

"enter".

2. Whack in this command from the Cnet Article Topher quoted above [needs a space in front]

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

BOOM!

You get a list of all the folders and subfolders only within the original folder / directory you specified in step one.

****** if I know what all that code means.

I'd love to know, but it looks pretty tech.

Just makes you admire the people who come up with this stuff so much.

Geenyoos!

...........

The only thing I'd love to know know would be how to exclude certain directories within the main directory from the final listing.

That might be the subject of another post though, I might have crapped-on enough!

Dec 19, 2012 5:10 AM in response to Benway1

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'


BOOM!

You get a list of all the folders and subfolders only within the original folder / directory you specified in step one.


****** if I know what all that code means.


It's fairly simple indeed.


You must broke up the line into 3 pieces, each piece ending at the | symbol.


ls -R


grep ":$"


sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'


The | (pipe) means that the output of the first command is the input of the following command.

You can try yourself executing each command in a separate Terminal window like this


1st Terminal window issue


ls -R | more


2nd Terminal window issue


ls -R | grep ":$" | more


3rd Terminal window issue


ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' | more


| more at the end tells the shell to pause the output at the end of the window page


Putting each window side by side you can see what every commands do.

Dec 19, 2012 4:53 PM in response to Alberto Ravasio

Awesome Alberto! Thanks a lot!

Terminal is slowly looking less intimidating 🙂


That pipe thing with multiple-terminal windows as you mentioned makes it seem like a kind of virtual-circuit with "|" being kind of resistors I guess eheh.


I think over time as I learn what the general abbreviations and acronymns actually mean, it will become easier.


It looks like jibberish at present, but I guess mostly it's just condensed english.


I still can't work out all the random backslashes and square-parentheses, hyphens etc.

but maybe that will just take some time learning.

is there a way to copy list of all folders sub folders 10.8.2

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.