How can I list folders that contain files with a specific file extension like .NEF

Discussion in 'macOS' started by stayathomedad, Feb 27, 2015.

  1. stayathomedad macrumors newbie

    Joined:
    Feb 22, 2011
    #1
    not the total path to the folder containing the files but rather just a parent folder one level up of the files.

    So file.nef that's in folder 1 that's in folder 2 that's in folder 3... I just want to list folder 1, not 2 or 3 (unless they contain files themselves in their level)
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Do you need to do this more than once?

    What is the base folder you need it done on? For example, are all the .NEF files you're looking for located under your home folder, or are they in various other places around your disk?


    If you need this done once, and your home folder is the base folder, then copy and paste the following into a Terminal window. It must be entered exactly as posted; accuracy is important.
    Code:
    find ~ -type f -iname "*.nef" \
      -exec bash -c 'd=$(dirname "{}"); basename "$d"' \;  \
      |  uniq  >~/nefs.txt
    
    The output will be collected in the file "nefs.txt" located in your home folder. You can open it in TextEdit after the Terminal command completes (the shell will reprompt).

    There are probably several other ways of doing this.

    If you need this done more than once, or done on a different base folder, then the above command can be revised and then put into an Automator workflow. You can then drop folders onto it, it will search them, and put the output in a designated file.
     

Share This Page