Printing the contents of a folder in MacOS 15.1.1 Sequoia

I have a folder with lots of entries, most of which are in subfolders up to 3 levels deep. How can I print the entire contents - folders, subfolders and files - of the top folder? I've seen some answers on here but they are old and the ones I tried didn't work. I suspect it may need something typing into Terminal (ooh, err).


Thanks.

MacBook Pro 16″, macOS 15.1

Posted on Jan 7, 2025 8:15 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 7, 2025 8:31 AM

You can get results pretty quickly with Terminal. Here is a step by step:


1) Open Terminal

2) Type "cd " (without quotes but with the trailing space); do NOT press enter yet

3) Drag the folder from Finder and drop it on the Terminal window

4) press enter

5) Type


ls -R | pbcopy


6) Open TextEdit, or your preferred text editor, and press Command-V to Paste


You can make any necessary adjustments, and print from there.


NOTE: If this is something you need to do often, it can be rather easily automated.

5 replies
Question marked as Top-ranking reply

Jan 7, 2025 8:31 AM in response to Flybr1dge

You can get results pretty quickly with Terminal. Here is a step by step:


1) Open Terminal

2) Type "cd " (without quotes but with the trailing space); do NOT press enter yet

3) Drag the folder from Finder and drop it on the Terminal window

4) press enter

5) Type


ls -R | pbcopy


6) Open TextEdit, or your preferred text editor, and press Command-V to Paste


You can make any necessary adjustments, and print from there.


NOTE: If this is something you need to do often, it can be rather easily automated.

Jan 7, 2025 8:56 AM in response to Flybr1dge

The second simplest visual approach (after ls -R) is in the Terminal using a script that I offer here:


#!/bin/zsh

: <<"COMMENT"
Create a folder hierarchy tree diagram by providing the starting folder name
as an argument to this script. Can be relative, tilde, or absolute path.

Usage: ./treex.zsh ~/Desktop/SampleFolder

Credit: Alice Purcell, https://stackoverflow.com/questions/14223233/list-all-directories-recursively-in-a-tree-format

COMMENT

STARTDIR="${1:a:s/\~\//}"
find "${STARTDIR}" -type d -print | sed -e 's;[^/]*/; /;g;s;/ ;    ;g;s;^ /$;.;;s; /;|-- ;g' |\
cut -c 12-
exit 0


You copy and paste the above content into a plain text file and save it as treex.zsh on your Desktop. Then in the Terminal, you want to make it executable and run it:


cd ~/Desktop
/bin/chmod +x ./treex.zsh
./treex.zsh /path/to/folder > tree.txt


You now have a text file on your Desktop that you can click on and press the space bar to view using the Finder's Quick Look feature.


The output will appear nested like the following to show the folder and file hierarchy:


Jan 7, 2025 9:44 AM in response to jblanchard1

The /Library/Scripts/Print Window With Subfolders.scpt, which is dated 2003, just does an ls -R on the selected folder in the Finder and pipes it to the default printer. The script must be copied to the user account as it cannot be run directly from that Library location.


That is a lot of AppleScript obfuscation to just achieve what Luis offered above. Worse if the printer is offline. ;-(.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Printing the contents of a folder in MacOS 15.1.1 Sequoia

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