How to get contents of folder into a .txt file?

Joined
Sep 6, 2008
Messages
869
Reaction score
0
Points
16
Your Mac's Specs
13" MBP - 2.7 Ghz, Intel Core i7, 8GB RAM.
I need the contents of a folder to be displayed in a .txt file, but unlike with Automator, I don't need the entire directory to be listed -- just the files as they appear in the folder.
 
Joined
Jul 2, 2007
Messages
3,494
Reaction score
204
Points
63
Location
Going Galt...
Your Mac's Specs
MacBookAir5,2:10.13.6-iMac18,3:10.13.6-iPhone9,3:11.4.1
open terminal, cd to the folder, type ls, then copy and paste into your text editor.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Easier....


ls > whatever_you_want_to_name_it.txt


ls -l if you want more information... ls -lh if you want filesizes to be human readable


ooooo if you really just want the FILES, not subdirectories..


find . -depth 1 -type file > filename.txt
 
OP
R
Joined
Sep 6, 2008
Messages
869
Reaction score
0
Points
16
Your Mac's Specs
13" MBP - 2.7 Ghz, Intel Core i7, 8GB RAM.
find . -depth 1 -type file > filename.txt

Where do I type that in? Do I start with the period?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
That is a command that you input into the Terminal (/Applications/Utilities/Terminal.app).
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
In addition to vansmith's excellent point (I completely forgot to mention how to get there) the find statement is the start of the command. So it will look like this..

mikeMbp:~ mike$ find . -depth 1 -type file > examlpleFile.txt
mikeMbp:~ mike$

Now the contents will look something like this..

./.ano
./.bash_history
./.CFUserTextEncoding
./.DS_Store
./.lesshst
./.profile
./.syncdocs
./.viminfo
./.Xauthority
./able.preferences
./ANALYS32.XLL
./dscli
./examlpleFile.txt

if the ./ is a problem we can ditch that by doing something like this...

find . -depth 1 -type file | sed 's:./: :' > examlpleFile.txt
 
Joined
Mar 30, 2004
Messages
4,744
Reaction score
381
Points
83
Location
USA
Your Mac's Specs
12" Apple PowerBook G4 (1.5GHz)
Geez. Why does everybody jump for the Terminal for such a simple problem?

Open a folder.
Choose Edit > Select All
Choose Edit > Copy
Open a text editor, such as BBEdit or TextWrangler.
(Important note: if you use TextEdit, make sure you are using Plain Text mode. By default, you can do this by choosing Format > Make Plain Text. You should not see the toolbar with Style and Line Spacing.)
Choose Edit > Paste
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
The only thing I have noticed with Dysfunction's idea, which I would have also suggested, is that the file you redirect output to (I think that's the right phrase) will also include the name of the file you redirect to. To clarify, let me show you.

If I execute ls > test.txt in my home directory, the content of test.txt is as follows:
Desktop
Documents
Downloads
Library
Movies
Music
Pictures
Public
Sites
test.txt

So, as you can see, the file you are trying to save the output of ls to is also included in that list. This also occurs for the aforementioned find command. One simple way around this would be to redirect to a file outside of the directory you are trying to get the contents of. So, for instance, you could execute the following:
Code:
ls > ~/Desktop/test.txt
If you prefer Dysfunction's find command above, you can also change the redirect file:
Code:
find . -depth 1 -type file > ~/Desktop/exampleFile.txt
Each of these will output the file to the desktop. You can of course change where the file is written to.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top