For Programmers: Free Programming Magazines  


Home > Archive > AppleScript > October 2005 > getting a file name from a path name









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author getting a file name from a path name
Hal Jordan

2005-10-30, 3:55 am

Woe is me.... I would have thought I could at least do a simple script
like this. I want to extract the file name from a list of files.
However, I get an error and the script never goes to the handler. The
error is "Can't continue processFiles". What is my problem? Thanks in
advance to the "all knowing scripting gurus".

on open (theList)
tell application "Finder"
repeat with thefile in theList
set FileName to processFiles(thefile)
end repeat
end tell
end open

on processFiles(thefile)
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's
text item delimiters, {":"}} set mytextfilename to last text item of
(thefile as text)
set AppleScript's text item delimiters to oldDelims
return mytextfilename
end processFiles

Gnarlodious

2005-10-30, 3:55 am


tell application "Finder"
set theList to every file of (choose folder)
get name of item 1 of theList
end tell

-- Gnarlie

Michelle Steiner

2005-10-30, 3:55 am

In article <1130643363.401306.42560@g47g2000cwa.googlegroups.com>,
"Hal Jordan" <drillbit_99@yahoo.com> wrote:

> However, I get an error and the script never goes to the handler.
> The error is "Can't continue processFiles". What is my problem?
> Thanks in advance to the "all knowing scripting gurus".


The script is telling the finder to run its processFiles routine, but
the finder doesn't have such a routine.

There's no need for the tell application "Finder" wrapper; you're not
using the Finder for anything there, so you can remove it. However, if
this is only part of the script and you actually do need the Finder
within the repeat loop for other purposes, the way to fix it is to
change

set FileName to processFiles(thefile)

to

set FileName to my processFiles(thefile)

The script will now know to use its own function and not to try to hand
it off to the Finder.

--
Stop Mad Cowboy Disease: Impeach the son of a Bush.
Michelle Steiner

2005-10-30, 3:55 am

In article <BF899FD4.16B98%gnarlodious@yahoo.com>,
Gnarlodious <gnarlodious@yahoo.com> wrote:

> tell application "Finder"
> set theList to every file of (choose folder)
> get name of item 1 of theList
> end tell


But that doesn't tell him why his code didn't work.

--
Stop Mad Cowboy Disease: Impeach the son of a Bush.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com