Ledge

How to copy a list of file names from a folder on a Mac

Select the files in Finder, press Command-C, then paste into a plain text document. You get the names, one per line, instead of the files. For bigger jobs, or when you want everything inside subfolders too, the ls command in Terminal sends the list straight to the clipboard or to a text file.

Copy the names with Finder and a plain text paste

  1. Open the folder in Finder. Press Command-A to select everything, or select only the files you want listed.
  2. Press Command-C.
  3. Open TextEdit and make a new document.
  4. Choose Format > Make Plain Text, or press Shift-Command-T.
  5. Press Command-V.

The names appear as a list, one on each line.

Step 4 is the one that matters. When you copy files in Finder, the clipboard holds more than one version of what you copied: the files themselves, and their names as text. A rich text document can hold files, so it takes those and embeds them as attachments. A plain text document can only hold text, so it takes the names. What the pasteboard holds when you copy a file goes into the detail.

The same rule applies everywhere else. A code editor, a search field or a plain text box in a web form will receive names. In an app that keeps embedding the files, try Edit > Paste and Match Style. If that still embeds them, paste into a plain text document first and copy the list from there.

A spreadsheet usually puts each name in its own row, which is handy for a checklist or an inventory. If yours inserts icons or images instead, go through the plain text document.

Two things to check once the list is pasted:

  • Extensions. Look at whether the names end in .pdf, .jpg and so on. If they do not and you need them, turn on Finder > Settings > Advanced > Show all filename extensions and copy again, or use the Terminal method below, which always prints the full name.
  • Order. Sort the Finder window the way you want before copying, by clicking a column header in list view. If the pasted order still is not what you need, sort the lines in your editor or spreadsheet.

Copy the name of one file

For a single name, there is a shorter route.

  1. Select the file in Finder and press Return. The name becomes editable, with everything before the extension highlighted.
  2. Press Command-C. To include the extension, press Command-A first so the whole name is highlighted.
  3. Press Escape to leave the name as it was.

Include what is inside subfolders

Finder can list nested files as long as they are visible.

  1. Switch the window to list view with Command-2.
  2. Click the disclosure arrow beside a folder to show its contents. Option-click the arrow to open every level inside it at once.
  3. Press Command-A. Every visible row is selected, including the nested ones.
  4. Copy, then paste as plain text.

The result is a flat list. It gives names only, with nothing to show which folder each file sits in. If that matters, you want paths rather than names, or the Terminal method.

List a folder with Terminal

Terminal is quicker for large folders and gives you more control over what the list contains.

  1. Open Terminal from Applications > Utilities.
  2. Type cd followed by a space, drag the folder from Finder into the Terminal window, and press Return. Terminal is now working inside that folder.
  3. Run one of these commands.

To copy the names to the clipboard, one per line:

ls | pbcopy

To write the list to a text file on your desktop:

ls > ~/Desktop/file-list.txt

To list every file in the folder and all of its subfolders, each with its location relative to the folder:

find . -type f | pbcopy

A few notes:

  • ls leaves out hidden files, the ones whose names begin with a dot. Use ls -A to include them.
  • To list one type only, add a pattern: ls *.pdf | pbcopy. The pattern is case-sensitive, so files ending in .PDF need their own pattern.
  • None of these commands changes anything. They read names and nothing else.

When you need paths, not names

A name tells you what a file is called. A path tells you where it is, which is what a command or a script needs.

Finder can copy paths directly. Select the files, open the Edit menu, and hold the Option key: Copy becomes Copy as Pathname. The shortcut is Option-Command-C. Paste anywhere and you get the full path of each file, one per line. How to copy a file’s path on a Mac has more ways to do it.

That works when the files share a window. It gets awkward when they are spread across several folders, because there is no single place to select them all.

Ledge helps with that case. As you come across each file, drag it up to the notch and let go; it lands on a shelf that drops from the notch and stays there. When the set is complete, open the shelf with Option-Space or a click on the notch and drag the files onto a terminal window. A terminal receives their paths as text, not the files. The first time Ledge pastes a path into a terminal for you, macOS asks for Accessibility permission; it is never requested at launch.

The same shelf hands other destinations what they can use. Dropped on a Finder folder, the files themselves move there. Dropped on a chat app, they upload.

To be plain about the limits: Ledge does not read or index your folders, and it will not produce a listing of a folder’s contents. For a list of names from one folder, copy and a plain text paste is the whole answer. The shelf earns its place when the files come from different folders and the destination wants paths. If those paths contain spaces, paths with spaces in the terminal, and how to avoid trouble is worth a read before you run anything.

Questions

Why did pasting put the files into my document instead of their names?

The document is rich text, which can hold attachments. Switch it to plain text with Format > Make Plain Text in TextEdit, or paste with Edit > Paste and Match Style.

Can I get sizes and dates in the list as well?

Not from a Finder paste, which carries names only. In Terminal, ls -lh > ~/Desktop/file-list.txt writes a list with sizes and modification dates. It is laid out for reading, so expect some tidying if it is headed for a spreadsheet.

Does this work for a folder on an external drive or a server?

Yes. Both the Finder paste and the Terminal commands work on any folder you can open, wherever it is stored.