{"id":511,"date":"2012-03-14T10:25:39","date_gmt":"2012-03-14T17:25:39","guid":{"rendered":"http:\/\/10.0.1.201\/?p=511"},"modified":"2012-03-14T10:25:39","modified_gmt":"2012-03-14T17:25:39","slug":"save-list-of-folder-contents","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2012\/03\/14\/save-list-of-folder-contents\/","title":{"rendered":"Save list of folder contents"},"content":{"rendered":"<p><ins datetime=\"2020-11-13T19:09:11+00:00\">[UPDATE] Revisited this one and made it a little nicer. It is faster and gives a total count of directories and files, skips invisibles (but you can undo that), and doesn&#8217;t error on item names longer than 31 characters. Confirmed to run on 10.4, YMMV.<\/ins><\/p>\n<p>This AppleScript will create a file containing a tree style list of all files inside the chosen directory and save that list in a file created in that directory. The list file will include the path of the listed directory as well as the date and time it was saved and a tally of me bananas&#8230; er, folders and files under the starting directory.<\/p>\n<p>The default directory in the choose dialog is the folder of the Finder&#8217;s frontmost window unless there are no Finder windows. In which case the default is the Desktop folder.<\/p>\n<p>It does not follow aliases (not sure about symlinks) and will indicate an alias by placing &#8221; [alias]&#8221; behind the file name.<\/p>\n<p>This is actually a modified version of a script that&#8217;s been around the web for years.<\/p>\n<p><code>-- http:\/\/strawhousepig.net\/<\/p>\n<p>set fileList to \"\"<br \/>\nset d_count to 0<br \/>\nset f_count to 0<br \/>\nglobal fileList, d_count, f_count<\/p>\n<p>on listFolder(f, s)<br \/>\n\tlist folder f as alias without invisibles<br \/>\n\trepeat with i in the result<br \/>\n\t\tset finfo to (info for alias (f & i))<br \/>\n\t\tif folder of finfo then<br \/>\n\t\t\tset d_count to d_count + 1<br \/>\n\t\t\tset fileList to fileList & s & i & \"\/\" & return<br \/>\n\t\t\tlistFolder(f & i & \":\", s & \"    \")<br \/>\n\t\telse<br \/>\n\t\t\tif alias of finfo then<br \/>\n\t\t\t\tset f_count to f_count + 1<br \/>\n\t\t\t\tset fileList to fileList & s & i & \" [alias]\" & return<br \/>\n\t\t\telse<br \/>\n\t\t\t\tset f_count to f_count + 1<br \/>\n\t\t\t\tset fileList to fileList & s & i & return<br \/>\n\t\t\tend if<br \/>\n\t\tend if<br \/>\n\tend repeat<br \/>\n\treturn {fileList, d_count, f_count}<br \/>\nend listFolder<\/p>\n<p>try<br \/>\n\ttell application \"Finder\" to set cwd to (POSIX path of (folder of window 1 as string)) as POSIX file<br \/>\non error<br \/>\n\tset cwd to path to desktop folder<br \/>\nend try<br \/>\nset theFolder to (choose folder \"Select a folder to list:\" default location cwd) as string<\/p>\n<p>--This will get the name of the folder for use in the name of the generated file<br \/>\nset folderName to name of (info for (theFolder as alias))<\/p>\n<p>--This will get the Unix style path of the folder for info purposes inside the file itself<br \/>\nset folderPath to POSIX path of theFolder<\/p>\n<p>set infoList to listFolder(theFolder, \"\")<br \/>\nset fileList to \"# File list of: \" & folderPath & \" on \" & (current date) & return & item 2 of infoList & \" folders and \" & item 3 of infoList & \" files total.\" & return & return & item 1 of infoList<\/p>\n<p>set listFile to ((theFolder) as text) & \"!File list of this folder (\" & folderName & \")\" & (do shell script \"date \\\"+ %Y-%m-%d %H%M\\\"\") & \".txt\"<\/p>\n<p>tell application \"Finder\"<br \/>\n\tset newFile to (open for access file listFile with write permission)<br \/>\n\tset eof newFile to 0<br \/>\n\twrite fileList to newFile<br \/>\n\tclose access newFile<br \/>\n\topen listFile as alias<br \/>\nend tell<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[UPDATE] Revisited this one and made it a little nicer. It is faster and gives a total count of directories and files, skips invisibles (but you can undo that), and doesn&#8217;t error on item names longer than 31 characters. Confirmed to run on 10.4, YMMV. This AppleScript will create a file containing a tree style [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10,28],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-code","tag-applescript-2","tag-os-x"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}