RE: how to detect the existence of a file ...
RE: how to detect the existence of a file ...
- Subject: RE: how to detect the existence of a file ...
- From: "Goodman, Steve" <email@hidden>
- Date: Fri, 26 Oct 2001 10:39:50 -0500
Here is a handler to get you going. If you pass it a path it will check to
see if it is there and then append an "_n" (n being a number strarting at 1)
and check for its presence. It will repeat until it finds the next open name
and return that name. Modify as needed.
HTH
-- ---------------------------------------------------------
set thefile to "dcs1532:Desktop Folder:Check"
checkexistence(thefile)
on checkexistence(thefile)
set thefile to thefile as string
set thecheckfile to thefile
set x to 1
repeat
try
thecheckfile as alias
set thecheckfile to (thefile & "_" & x) as string
set x to x + 1
on error
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set newname to text item -1 of thecheckfile
set AppleScript's text item delimiters to oldDelims
return newname
end try
end repeat
end checkexistence
-- ---------------------------------------------------------
Steve Goodman
Vertis Advertising Production Services
phone 314.432.8800, ext. 479
fax 314.692.0309
email@hidden
www.vertisinc.com
>
----------
>
From: Arthur Cormack
>
Sent: Thursday, October 25, 2001 2:44 PM
>
To: email@hidden
>
Subject: how to detect the existence of a file ...
>
>
---sorry about the repost
>
>
Greetings and Salutations , Applescript Lords and Ladies.
>
>
A quick question from a humble squire:
>
>
i have created a droplet that renames files - server log files,
>
based on the dates of the logs in them - and it works quite nicely
>
... except for when there is/would be a duplicate filename made ...
>
i need to pre-empt this conflict by checking to see if a file by the
>
name of the name that we would call the logfile that we are currently
>
working with exists. And ... if it does ... add a suffix integer to
>
the filename which indicates which duplication number it is. It will
>
also check for multiple duplicates by looking at the integer as well.
>
There is one obstacle that I am having trouble with. How do I check
>
to see whether or not a file exists?
>
>
regards,
>
>
and thanks,
>
>
arthur cormack
>
_________________________
>
producer, interactive
>
the online group, TVOntario
>
W:416.484.2600.2010 C: 416.453.4369
>
E: email@hidden
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users