Re: Is my logic wrong here?
Re: Is my logic wrong here?
- Subject: Re: Is my logic wrong here?
- From: Rick cougar Bargerhuff <email@hidden>
- Date: Tue, 04 Feb 2003 13:20:22 -0500
Hey Jeff!
On Tuesday, Feb 4, 2003, at 08:44 US/Eastern, Jeff Whitmill wrote:
I'm trying to write a script to compress web server log files with
GZipper.
The files I need to compress have 2 characteristics in their names:
They all end in ".log.txt" and they all contain the string "_200".
Thanks to some generous help on this list, this is being accomplished:
You're welcome bro, any time.
try
with timeout of 20 seconds
tell application "Finder"
activate
set theFolder to
"MyDisk:Applications:Server:Webserver:MySite:My_Admin:Logs:CurrentLogs:
"
select (every file of folder theFolder whose name ends with
".log.txt" and name contains "_200")
open selection using application file
"MyDisk:Applications:GZipper"
end tell
end timeout
end try
However, in testing various scenarios, i came upon one that really
fouls things up:
If there are no files meeting the criteria, the script compresses the
remaining selection - which is the script itself (selected from my
having double-clicked on it). I've lost a couple of copies of the
script this way.
I don't know if this will be a problem when the script is called by a
scheduler (say, Cron, or something like it) - but I'd hate to think
there might be something inadvertently selected when this runs.
How do I limit the actions to the files in the folder I'm examining?
Am I going about this the wrong way?
Lets try this instead...
try
set theFolder to
"MyDisk:Applications:Server:Webserver:MySite:My_Admin:Logs:CurrentLogs:"
set thefiles_temp to list folder theFolder
set thefiles to {}
repeat with i from 1 to (count of thefiles_temp)
set thefile to item i of thefiles_temp
if (thefile contains ".log.txt") and (thefile contains "_200") then
set end of thefiles to thefile
end if
end repeat
with timeout of 20 seconds
tell application "Finder"
activate
repeat with i from 1 to (count of thefiles)
set thepath to file (theFolder & (item i of thefiles)) as string
select file thepath
open selection using application file
"MyDisk:Applications:GZipper" end repeat
(* OLD Code
--select (every file of folder theFolder whose name ends with
".log.txt" and name contains "_200")
*)
end tell
end timeout
end try
Jeff, this I believe is more safer, and what it will do is process each
file as it is selected instead of selecting all the files at once and
then
processing them using GZipper.
Good luck!
Rick Bargerhuff
Programmer / Developer
Multi-platform Technician / Specialist / Web Designer
Personal Email: email@hidden
Personal Website :
http://mywebpages.comcast.net/cougar718
_______________________________________________
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.