• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Index a given folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Index a given folder


  • Subject: Re: Index a given folder
  • From: "Mark J. Reed" <email@hidden>
  • Date: Sat, 3 Apr 2010 22:02:39 -0400

Here's one way:

set theFolder to (choose folder with prompt "Choose folder to index")

tell application "System Events" to set indexName to name of theFolder

set targetFile to (choose file name with prompt "Choose where to save index" default name (indexName & "-index.txt") default location (path to desktop))

tell application "System Events" to set fileList to the name of (items of theFolder)

set text item delimiters to return & linefeed

write (fileList as text) to targetFile

The result is sorted alphabetically in my testing, but I don't know if that's guaranteed by System Events, or if so, what version of OS X that guarantee begins with. 

You can replace the last three lines with a call out to the shell:

do shell script "ls " & (quoted form of POSIX path of theFolder) & ">" & (quoted form of POSIX path of targetFile)

which will always be sorted.

On Sat, Apr 3, 2010 at 9:38 PM, Jason Donnelly <email@hidden> wrote:
Hi there,

I'm fairly new to AppleScript, hope this isn't going to be overly 'newbie' for the experienced users -- seems like it should be fairly easy -- but I'm stuck.

How can I create a text file index of a given folder?

As in, I'm trying to create a script which can:

1.  be pointed to a chosen folder,

2.  will get the names of every file in that folder,

3.  generate a text file which lists all the files in that folder (order doesn't really matter, but alphabetical would be nice), and

4.  save the text file to Desktop.

That's all I want it to do.

Again, sorry if this is painfully newbie.

Thanks,

J. Donnelly.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



--
Mark J. Reed <email@hidden>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Index a given folder
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Index a given folder (From: Jason Donnelly <email@hidden>)

  • Prev by Date: Index a given folder
  • Next by Date: Re: Index a given folder
  • Previous by thread: Index a given folder
  • Next by thread: Re: Index a given folder
  • Index(es):
    • Date
    • Thread