Newbie - Setting variable to file name

Allright,

extreme newbie question;

I’m working on a project and everything else works swimingly except for this. I need to set the value of a variable to the name of a file located within a specific folder. I know this should be easy, but every time I try it, the value end up being the entire path to said file…

Ideas? Thanks…

set targetFile to choose file
tell application "Finder" to set fileName to name of targetFile
display dialog fileName

I’m sorry, I didn’t make myself clear. The file name, and location will be static, so I want the script to be able to do this automatically.

Maybe it would be easier if you provide the bit of code that’s giving you problems. :slight_smile:

True… hehehe. :wink:


tell app "Finder"
                set myName to the first file of folder "XYZ" of disk "ABC"
                 display dialog "The File Name is  " & (myName)
end tell

Does that make it any clearer? When the script is run, instead of just returning the name of the file in the specified folder, it returns the entire path. “The File Name is ABC:XYZ:Filename”

Ideas as to what I’m doing wrong?

Yep, that helps a lot. The script is asking for the file and not the name of the file.

Does this work?

tell app "Finder"
                set myName to name of the first file of folder "XYZ" of disk "ABC"
                 display dialog "The File Name is  " & (myName)
end tell

:slight_smile:

Argh… yes, that was it! So simple. smacks self in forhead Thanks for your help!! :smiley: