occassia

Q: How can I export a list of filenames from Finder as text?

I can Copy from a window and Paste into a word processor / text editor, but date/size/filetype info is lost.

MacBook Pro, Mac OS X (10.6.3)

Posted on Jul 26, 2014 4:54 PM

Close

Q: How can I export a list of filenames from Finder as text?

  • All replies
  • Helpful answers

  • by Niel,

    Niel Niel Jul 26, 2014 6:16 PM in response to occassia
    Level 10 (313,375 points)
    Mac OS X
    Jul 26, 2014 6:16 PM in response to occassia

    Open the AppleScript Editor in the /Applications/Utilities/ folder and run the following exactly as posted:

     

    set the_string to ""

    tell application "Finder"

    repeat with this_item in (get items of (choose folder))

    set the_string to the_string & name of this_item & tab & modification date of this_item & tab & size of this_item & tab & kind of this_item & return

    end repeat

    end tell

     

    Paste the result into the word processor.

     

    (110029)

  • by occassia,

    occassia occassia Jul 26, 2014 6:39 PM in response to Niel
    Level 1 (8 points)
    Mac OS X
    Jul 26, 2014 6:39 PM in response to Niel

    Nifty! I'm assuming that (choose folder) should be replaced with (folder name) —with or without parens?

  • by Barney-15E,

    Barney-15E Barney-15E Jul 26, 2014 6:41 PM in response to occassia
    Level 9 (50,344 points)
    Mac OS X
    Jul 26, 2014 6:41 PM in response to occassia

    There are third-party programs that do this. I think Print Folder is one. I’ve never used it.

     

    You can also create an automator action to print the details from the command line.

    Create a new Service and set it up like this:

    Screen Shot 2014-07-26 at 8.41.14 PM.png

    The shell script is this:

    ls -ohkFRT Documents | awk '{print$9"\t"$4"\t" $5, $6", "$8, $7}'
    
    

    If you don’t want to recursively list the subdirectory contents, remove the R, like this:

    ls -ohkFT Documents | awk '{print$9"\t"$4"\t" $5, $6", "$8, $7}'
    
    

    If you don’t want to see the / after folders and the * for executables, remove the F, like this:

    ls -ohkRT Documents | awk '{print$9"\t"$4"\t" $5, $6", "$8, $7}'
    
    

    Save the Service as Print Folder Contents (or anything you want). You can ctrl-click on a folder in the Finder and choose Print Folder Contents from the Services menu. This will open a new Text Edit document with the name, size, and date listed in a tab-delimited file.

  • by Niel,

    Niel Niel Jul 26, 2014 6:42 PM in response to occassia
    Level 10 (313,375 points)
    Mac OS X
    Jul 26, 2014 6:42 PM in response to occassia

    As I wrote above, run it exactly as posted. This means not replacing 'choose folder' with anything else.

     

    (110035)

  • by occassia,

    occassia occassia Jul 26, 2014 6:45 PM in response to Niel
    Level 1 (8 points)
    Mac OS X
    Jul 26, 2014 6:45 PM in response to Niel

    So cool! Thank you Niel!

     

    Thank you also, Barney. ;-)

  • by dougweaver4,

    dougweaver4 dougweaver4 Aug 19, 2014 1:40 PM in response to Niel
    Level 1 (0 points)
    Aug 19, 2014 1:40 PM in response to Niel

    Niel, thanks for the script, but when I pasted it into AppleScript and saved it and ran it i got an alert: Syntax Error, A unknown token can't go after this "".

    Syntax Error, A unknown token cant go after this %22%22.tiff

    Any idea what went wrong?

     

    Thanks,, dw4comp

  • by Barney-15E,

    Barney-15E Barney-15E Aug 19, 2014 1:52 PM in response to dougweaver4
    Level 9 (50,344 points)
    Mac OS X
    Aug 19, 2014 1:52 PM in response to dougweaver4

    It sounds like you have copied some artifact from the web display, or you missed part of the code.

    From Safari, copy/paste of the entire code worked fine. Are you using another browser? It may have inserted something into the lines.

    set the_string to ""
    tell application "Finder"
      repeat with this_item in (get items of (choose folder))
      set the_string to the_string & name of this_item & tab & modification date of this_item & tab & size of this_item & tab & kind of this_item & return
      end repeat
    end tell
    
    
  • by dougweaver4,

    dougweaver4 dougweaver4 Aug 20, 2014 11:30 AM in response to Barney-15E
    Level 1 (0 points)
    Aug 20, 2014 11:30 AM in response to Barney-15E

    Thanks... I copied from his reply in Safari and it gave that error, but when I copied from yours in Safari it worked. This will be useful.

     

    BTW, from another forum entry I found an Automator workflow that creates a text file of the file &/or folder names in a folder, but it does not capture the size, date etc, at least as I found it. Link or screenshot available on request. I had some trouble getting it to work as a Service until I figured out something that the OP of it had left off.

  • by iDome90,

    iDome90 iDome90 Jan 7, 2015 3:09 AM in response to Niel
    Level 2 (229 points)
    Jan 7, 2015 3:09 AM in response to Niel

    Thank you so much for this TOP answer.

  • by plutopaul,

    plutopaul plutopaul May 19, 2015 2:39 PM in response to Barney-15E
    Level 1 (0 points)
    May 19, 2015 2:39 PM in response to Barney-15E

    Thanks for this. I switched off the recursive switch for sub-directories and have it nearly working, save that it doesn't produce a list from the current folder, but always from the root? Any ideas?