Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if statement



I think there are several problems that you may be having, First of all, when the first if statement works then the file will be moved and will not be around for subsequent if statements, causing the script to have an error and quit. Secondly if you use "characters 6 thru 7" you will get a list of both characters, not a string that you can use to compare to another string. You should use "text 6 thru 7" instead Lastly you should do a check to see if the file name is larger than 6 characters so the "text 6 thru 7" statement works.

The following code seems to work fine. I nested the if statements as I think you wanted them and I changed the "characters 6 thru.." to "text 6 thru..." so that you would be comparing a string to a string instead of a list to a string. I also added the file name length sanity check.

- Ken

code:
--------------
property hotfolder : ((path to desktop as string) & "Data:";)
property errorfolder : (hotfolder & "deadfiles:")

tell application "Finder"
set flist to every file of folder hotfolder
repeat with curfile in flist
set nm to name of curfile as string
if nm contains "id" then
if (length of nm is greater than 6) then
if (text 6 thru 7 of nm) = "id" then
move file (hotfolder & nm) to folder errorfolder with replacing
end if
end if
else
if (length of nm is greater than 6) then
if (text 6 thru 7 of nm) = "gs" then
move file (hotfolder & nm) to folder errorfolder with replacing
end if
end if
end if
end repeat
end tell
--------------


On Nov 26, 2003, at 12:03 PM, Ruby Madraswala wrote:

Can anyone tell me why the second if statement does not work, while the third if statement works.

Property hotfolder: "Data"
Property errorfolder: "Data:deadfiles:";
Tell application "Finder"
Set flist to every file in folder hotfolder
Repeat with curfile in flist
Set nm to name of curfile as string
(1) If nm contains "id" --- works
Move file (hotfolder & nm) to folder errorfolder with replacing
End if
(2) If characters 6 thru 7 of nm = "id" - doesn't work, no error message, script exits and does not process remaining files in the folder.
Move file (hotfolder & nm) to folder errorfolder with replacing
End if
(3) If characters 6 thru 7 of nm = "gs" - works
Move file (hotfolder & nm) to folder errorfolder with replacing
End if
End tell


Filename: v8888id ("id" is always the 6th and 7th character of filename)

Thanks in advance
Ruby
_______________________________________________
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.
_______________________________________________
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.

References: 
 >if statement (From: "Ruby Madraswala" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.