3

I know that I can open the file information dialogue (Get Info) for several files at once using ⌘⌥I and hide/unhide file extensions. How do I accomplish this for all files in a directory tree (including files in subfolders)?

5

You can easily do this in Terminal with the SetFile command:

To hide file extensions in a directory and all sub-directories:

cd <path to directory>

find . -name "*.*" -exec SetFile -a -E '{}' \; | echo "hiding extensions"

(can change the second * to a particular extension type if you choose)

To show file extensions in a directory and all sub-directories:

cd <path to directory>

find . -name "*.*" -exec SetFile -a -e '{}' \; | echo "showing extensions"
  • I think you meant to say "-a e", not "-a -e". "e" designates the extension you're changing. It's the argument to "-a". – Ray Sep 21 '14 at 22:21
  • @Robert, It works the same with or without the -. – l'L'l Sep 23 '14 at 4:17
  • SetFile is deprecated since Xcode 6. – Franklin Yu Nov 8 '18 at 5:48
3

Ok, I found a solution using Hazel:

I created a rule based on their posting How to get Hazel to go into subfolders:

If (…) Kind is Folder

Do the following (…) run rules on folder contents

The next rule selects a certain set of files, e.g.

If (…) Kind is pdf

Do (…) Run AppleScript embedded script

The script is

tell application "Finder"
    set extension hidden of theFile to true
end tell

I defined more conditions more different file types, so it doesn’t work on all files as requested. With a limited number of different file types this should be no problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .