• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
how do you tell what folder a file is in? - how to tell if a file exists part II
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how do you tell what folder a file is in? - how to tell if a file exists part II


  • Subject: how do you tell what folder a file is in? - how to tell if a file exists part II
  • From: "Arthur Cormack" <email@hidden>
  • Date: Fri, 26 Oct 2001 13:46:17 -0400

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


  • Follow-Ups:
    • Re: how do you tell what folder a file is in? - how to tell if a file exists part
      • From: "Arthur Cormack" <email@hidden>
References: 
 >can't wait for AppleScript Studio (From: "Ted Wood" <email@hidden>)

  • Prev by Date: Re: Default AppleScript Formatting
  • Next by Date: Re: how do you tell what folder a file is in? - how to tell if a file exists part
  • Previous by thread: can't wait for AppleScript Studio
  • Next by thread: Re: how do you tell what folder a file is in? - how to tell if a file exists part
  • Index(es):
    • Date
    • Thread