List files in flatten structure

I have the following question.
Is it possible to see all files of a folder and all folders below it, for example in a new Finder window in a flat structure without moving files.
(In Total Commander (Windows) the command Tree View (CTRL+B))
The trigger is e.g. right-click and choose a quick task or selecting the folder and a keystroke.


Result in new Finder window:

if you want to do it from Terminal:

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'



I don’t know a KM way of doing this, but it seems like you could do a Spotlight search and tell it to just show you documents and not folders and it would give you what you’re looking for.

Unless I’m misunderstanding something.

It is not clear if you just want a list of file names in your folder hierarchy, or if you actually want a new Finder folder with aliases to all of the files.

Here is an EXAMPLE to will produce just a list of file names in the Parent folder, and all sub-folders. I makes uses of the Bash find Command.

Example Output


Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.


MACRO:   Get Simple List of File Names in Parent Folder & Sub-Folders [Example] @Find @Bash

--~~~ VER: 1.0    2020-03-03 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Simple List of File Names in Parent Folder & Sub-Folders [Example] @Find @Bash.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.




  • Demo Get Simple List of File Names in Parent Folder & Sub-Folders

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.


  1. KM 8.0.2+
  2. macOS 10.12.6+ (Sierra+)
  3. Bash find Command Manual


  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    • ALL Actions that are shown in the magenta color
    • CHANGE Path of Parent Folder to be Searched in Bash Script Action


  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

@tjluoma, you're the shell script expert here. So, if you have the time and interest, I'd appreciate it if you could review the Bash script I used above to see if there are any issues and/or improvements you'd suggest.


{ read myFolderToSearch; read myRootFileName; read myFileExt; }


# --- DEFAULT VALUES If NOT Passed Via stdin ---

# --- Expand Tilde in Path if It Exists ---

echo Parent Folder: "$parentFolder" 

find -s "$myFolderToSearch" -type f  -name "$myRootFileName.$myFileExt" -name "[!.]*"

# --- Additional Parameters Your Can Use ---
# ADD   -name "[!.]*"    to exclude HIDDEN files (begin with a dot)
# ADD   -maxdepth 1      to limit to Parent folder


That's close, but the last part is incorrect.

First, I always use -iname with find because macOS is almost always installed case-insensitive.

Second, I recommend using -ipath to match any item which has a / followed by a literal .

To exclude matches to that -ipath you would put a \! in front of it, so the final version would look something like this:

find -s "$myFolderToSearch" -type f \
-iname "$myRootFileName.$myFileExt" \! -ipath '*/\.*'

Note that I broke it into two lines for readability. The \ after -type f tells the shell that the next line continues the command. If you put it all on one line you can (and should) just remove that \ but don't remove the other ones that are not at the end of line.

Thanks for the feedback.
I assume you are talking about -name "[!.]*"

What is wrong with it?
I took that term from here:

It seems to work OK in my testing.

Noted. I agree, it makes good sense.

I don't think I have that pattern. Where do you see it?

These seem functionally identical to me, with my limited knowledge of Bash:

-name "[!.]*"

\! -ipath '*/\.*'

How are they different?

I wonder if we're seeing a difference between bash and zsh. In zsh I get an error, based on the ! inside of a "

I have no idea. I don’t even know how to run ZSH.

Since I, too, am not certain if I'm properly understanding the goal, this may or may not be helpful. There is a built-in Mac command for revealing the contents of folders displayed in a Finder window.

With a Finder window open and set to List View (View > As List), select the desired folders (or all window contents using Command-A), then press Option-[right arrow]. This will expand all folders and their subfolders, thus showing all folder contents. To reverse this—also known as collapsing folders—press Option-[left arrow].

Note, to just expand all selected folders but not subfolders, skip the Option key and use only [right arrow].

First of all, thank you all very much for your answers.
I found a workaround myself: I go to a folder and make a new smart folder. As the search argument I take a point and then I have 99.9% of the files. I miss only the files with a '.'.
This view is what I meant my my perhaps somewhat unfortunate and not fully formulated question.

Now it might be possible to make a solution with KM so that I can toggle between the tree view and the flattened view with a key combination?