Re: how do you tell what folder a file is in? - how to tell if a file exists part
Re: how do you tell what folder a file is in? - how to tell if a file exists part
- Subject: Re: how do you tell what folder a file is in? - how to tell if a file exists part
- From: "Arthur Cormack" <email@hidden>
- Date: Fri, 26 Oct 2001 14:27:25 -0400
Well ... I have come up with this ( It's a little convoluted but it
works ) :
on getParentFolder(whichOne) --which one is an alias to a file
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set thisOne to the text items of (whichOne as text)
set thisTextItemCount to count the (text items of thisOne)
set thisFullPathToFolder to ((text items 1 thru (thisTextItemCount -
1) of thisOne) as text) --& ":"
set AppleScript's text item delimiters to oldDelims
return thisFullPathToFolder
end getParentFolder
--there must be a more direct route to finding this
thanks again,
A.
email@hidden writes:
Hello again.
Thanks to Steve Goodman who has provided a lead ... I am much further
along.
My strategy for checking for the existence of a file works like this:
I have a droplet which reads log files, and changes the names of
those logfiles to the dates that are actually found in the log files.
The problem I am having arises when there is a duplicate filename
that would be created.
I need to be able to check for the existence of a file in the same
directory with the same name. - and then cycle in a repeat loop,
incrementing an integer suffix, until a match is not found.
The way that I think I should look for the match is like this:
I make a list of all the files in the same directory as the file in
question (known as eachone in the following script )
and cycle through that list, looking for a match.
<Doh!!>But how do i find out which directory the file is in?</doh!!>
regards,
and thanks.
Arthur
Here is the script:
------------
on open (itemList)
--display dialog "Set this as the start of logfile name for all
selected files:" default answer ""
--set fol to (choose folder with prompt "choose a folder to put
these renamed log files") --this is also the folder to inspect
--how do we know which directory
display dialog "Set the prefix for all selected files:" default
answer ""
set prefix_string to the text returned of the result
display dialog "Set the suffix for all selected files:" default
answer ""
set suffix_string to the text returned of the result
set start_date_char to "["
set end_date_char to "]"
set date_delimeiter to "/"
--display a dialog to get the prefix
--get the suffix
repeat with eachOne in itemList
tell application "Finder"
--set the comment of eachOne to comment_string
set log_filename to eachOne as string
end tell
--set thisWord to getTheDateOfThisLogFile()
set thisWord to getTheDateOfThisLogFile(log_filename, line_pos,
start_date_char, end_date_char) --this returns a datelist (year,
month, day)
--global gDay, gMonth, gYear
set thisYear to item 1 of thisWord
set thisMonth to item 2 of thisWord
set thisDay to item 3 of thisWord
set thisName to prefix_string & "_" & thisYear & "_" & thisMonth &
"_" & thisDay & "." & suffix_string
--look for a duplicate of thiisName ... if found then change
thisname to something else ...
tell application "Finder"
activate
set the name of eachOne to thisName
--this is where the problem occurs
end tell
end repeat
end open
------------------
checkexistence
is there an easy way to find out the name of the directory that a
file is in?
on checkexistence(thefile)
--the file has to be passed as list
--need to find out which folder/directory a file is in
--then make a list that contains all the files that begin
--with the chosen prefix found in this directory (all relevent files
share same prefix)
--then cycle through that list looking for a match,
--if match is found, then append an integer to the end of the
returned filename,
--and keep checking until a match is not found
end checkexistence
_______________________________________________
applescript-users mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/applescript-users