• 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
Basic Finder operations (was Re: Beginners question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Basic Finder operations (was Re: Beginners question)


  • Subject: Basic Finder operations (was Re: Beginners question)
  • From: email@hidden (Michael Sullivan)
  • Date: Mon, 18 Mar 2002 16:35:28 -0500
  • Organization: Society for the Incurably Pompous

Miklos L Ranky writes:

> A really stupid question, but how do I:
> -choose a folder with a dialog and put all the files (path) in that folder
> to a list

To put a folder alias of the user's choice into a variable do the
following:

set theFolder to choose folder as alias

Getting a list of all the files in the folder has a complication -- do
you want to recurse through all subfolders? Or do you just want the
list of files on the top level? The first is easy. The second requires
a handler to take care of well.

Here's a quick script that puts a list of all the files recursively into
a list (but does not include folders, only files, although it searches
through all subfolders)

---begin script:

(*

All code lines end with the comment starter "--" to make obvious any
wraps that have occured.

WARNING: This is for example only, not a production script, and has not
been fully tested. Anything used for production should have many error
checks that this script lacks. (MES 2002)

*)

set theFolder to (choose folder) as alias --

set theBigList to generateRecList(theFolder) --


-- Handler to generate recursive list from a folder
on generateRecList(aFolder) --

tell application "Finder" --

set theFileList to every file of aFolder --
-- This line by itself will give you a list of top level files.
set theFolderList to every folder of aFolder --

if (count of theFolderList) is not 0 then --

repeat with i in theFolderList --
set theFileList to theFileList & my generateRecList(i) --
end repeat --

end if --
end tell --

return theFileList --

end generateRecList --

---- :end script

> -how do I access that list

What do you wish to do with it?

you can say

set theFile to item 1 of theBigList

and theFile will contain an alias to the first file in theBigList.

You can do a loop like this:

repeat with theFile in theBigList
-- do stuff here on each file using i as a file alias.
end repeat

This will repeat through the whole list with i as each file in turn.

> -how to do string manipulation with a path

Again -- what do you wish to do? AS has a whole bunch of string
manipulation functions. To get the path of the file just do

set aPath to (some reference to a file alias) as string

for instance, using the above script you could do:

set aPath to item 1 of theBigList as string

to get the path of the first file in the generated list.

The path will be of the form:

"DiskName:FolderName:SubFolderName:SubFolder2Name:...:FileName"

The colon separators, combined with the fact that a colon is not a valid
filename character means you can turn a path into a list with text item
delimiters:

set {oldTIDs, text item delimiters} to {text item delimiters, ":"}

set aPathList to text items of aPath

set text item delimiters to oldTIDs

> Does anybody know where can I find samples or manuals on this topic

Well, this may have been a start. also try Apple's website, and Danny
Goodman's Applescript book.

The key is to try stuff, look at the results and ask questions here when
you get completely stumped

Also -- use the dictionaries once you've learned how to read them.


Good Luck,

Michael

--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Basic Finder operations (was Re: Beginners question)
      • From: "Miklos L. Ranky" <email@hidden>
References: 
 >Beginners question (From: "Miklos L. Ranky" <email@hidden>)

  • Prev by Date: Check for a space at the end of a filename?
  • Next by Date: Re: Open files
  • Previous by thread: Beginners question
  • Next by thread: Re: Basic Finder operations (was Re: Beginners question)
  • Index(es):
    • Date
    • Thread