I just want to select all the files in a folder and ... I am too new..

Hi,

I have a folder with files within. I just want to select all of them and I do not know how. I tried to open the folder and keystroke “a” with command down but it does not work…

please help a dumb guy !

Patimages,

typically I set the path to the folder or prompt for the folder then get all the files in the folder like this


set aFolder to choose folder with prompt "choose a folder to processs"
tell application "Finder"
	set theFiles to files in aFolder
         repeat with afile in thefiles
         --- your code to do something with a file here
         end
end tell

what is your ultimate goal ?

it may be helpful for you too pick up a book and do some examples.

MM

thanks a lot !

my goal is to copy all the files from a folder to a program. There is no other (such as duplicate) with this bloody program… In other words, I need command+a, command+c. Actually, do you keystroke “c” to copy all or there a more elegant way?
you are absolutely write concerning my need to learn. would you recommand a book or even better, an online site ?

thank you so much for your time !

I recommend O’reilly’s AppleScript the definitive Guide written by Matt Neuburg. Thats the book that i have
I think there are some areas on this site that may have some introductory lessons but I’m not sure.

What program are you using and what do you want to do with the files once you have them open in your program ?

mm

A more generic and surefire way to find all the files in a folder, even if there are folders within the folder goes like this:


set tFldr to choose folder with prompt "Please choose the target folder"

tell application "Finder"
	try
		set tFiles to files of entire contents of tFldr as alias list -- works for many
	on error -- if there is only one file in the folder "as alias list" fails.
		set tFiles to files of entire contents of tFldr as alias as list -- works for one
	end try
end tell
-- at this point, tFiles is an AppleScript list of aliases to every file in the target.

You can’t “copy” a file, so you’ll have to be more explicit about what you really want to do.

Hi,

Would this work to select just one type of file on a folder? e.g. .mov files?

Cheers

Dan

Sure. You use a filter statement like this: (if you’re running Leopard, you don’t need the try block – that bug has been fixed).

set fldr to choose folder
tell application "Finder"
	set F to (files of entire contents of fldr whose name extension is "mov") as alias list
end tell

You can also choose by type:

set fldr to choose folder
tell application "Finder"
	set F to (files of entire contents of fldr whose file type is {"MooV"}) as alias list
end tell