0

I'm developing a little desktop application that lists the files in a given directory.

app

The table on the left gets compared to the table on the right. If anything on the right is missing, the text of the files on the left will turn red. Simple.

What I'm throwing at these tables is a path that contains multiple subfolders of images. These are saved as a variable so I cannot explicitly declare "omit a directory with this name".

Using this as an example:

directory

I get this output:

before

And I'd like to get this output:

after

How do I get the find command to return ONLY the file names? No directory names at all. Is this possible?

As of now I have:

"find -x  "+ path + " | sed 's!.*/!!' | grep -v CaptureOne | grep -v .DS_Store | grep -v .cop | grep -v .cof | grep -v .cot | grep -v .cos | grep -v Settings131 | grep -v Proxies | grep -v Thumbnails | grep -v Cache | sort"

This does get me only the file names and not the full paths. Which I want. And it doesn't include other file extensions and folders that I know will exist.

Like I said - I've never gone down this path and the above code could probably be done in a much easier way. Open to suggestions!

Michael
  • 111
  • 7

1 Answers1

1

To limit yourself to files, use -type f (to exclude directories, you'd use ! -type d). To get just the basename, pipe the output through basename. All together, that'd be:

find . -type f -print0 | xargs -0 basename

(The -print0 and -0 uses NUL as the separator so that whitespace in pathnames is preserved.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610