OS9 Copy files to other folder

Hello!

I’m really new with Applescript, so I have to learn a lot about applescript.

Request: In a folder there are a lot of files. All the filenames begin with 4PW and after the PW there could be other characters. I need a script that copy files from that folder who starts with 4PWEN to another folder.
I can only test this script at work.


Tell application "finder"
	Set files to the name of the list whose name contains "4PWEN" in "Macintosh hd"
	Duplicate files to desktop folder	
End tell

Is this the wright manner to copy the files that must begin with 4PWEN?

I have tried also to work with wildcards like ? * like in DOS or windows, but applescript crashed when I used this manner.
When there are better suggestions, please tell me!

Hello,

This weekend, I wrote a new code:


property path: "macintosh hd:desktop folder:1_ps-files Xtranet English"
property watchfolder: "macintosh hd:desktop folder:1_ps-files Xtranet"

tell application "finder"
set filelist to get the name of every file of folder watchfolder as list
repeat with thisfile in filelist
if (characters 1 thru 5 of thisfile) = "4PWEN" then
duplicate (item i of filelist) to path
end if
end repeat
end tell

The script must look in watchfolder for files who begins with 4PWEN en must copy these files to path.
The script gives nothing as result. Which fault I made?

Kindly regards,

Hi Jesse,

in the repeat loop the index variable thisfile is a reference to the list item, not to its contents.
In case of a boolean comparison you must explicitly dereference the value in this way

if (characters 1 thru 5 of contents of thisfile) = "4PWEN" then

which is the same as

if contents of thisfile begins with "4PWEN" then

This code avoid the repeat loop ( I hope it works also in OS 9 ;)):

property thepath : "macintosh hd:desktop folder:1_ps-files Xtranet English:"
property watchfolder : "macintosh hd:desktop folder:1_ps-files Xtranet:"
tell application "Finder" to duplicate (files of folder watchfolder whose name begins with "4PWEN") to folder thepath

Note: path is a reserved word. I recommend to use a different name of the variable