Thursday, September 19, 2019

#1 2007-10-26 11:40:24 am

JesseV
Member
Registered: 2006-11-21
Posts: 5

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.

Applescript:


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!

Offline

 

#2 2007-10-29 02:32:31 am

JesseV
Member
Registered: 2006-11-21
Posts: 5

Re: OS9 Copy files to other folder

Hello,

This weekend, I wrote a new code:

Applescript:


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,


Filed under: Finder

Offline

 

#3 2007-10-29 02:56:01 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11598
Website

Re: OS9 Copy files to other folder

JesseV wrote:

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?


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
[code]if (characters 1 thru 5 of contents of thisfile) = "4PWEN" then[/code]
which is the same as
[code]if contents of thisfile begins with "4PWEN" then[/code]
This code avoid the repeat loop ( I hope it works also in OS 9 wink):

Applescript:

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

Last edited by StefanK (2007-10-29 03:00:37 am)


regards

Stefan


Filed under: Finder

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)