Page 1 of 1

How to extract a dir path from file?

Posted: Tue Dec 01, 2009 12:34 am
by ale870
Hello,

I cannot find any function to extract the path of a file. I know it is easy to do, but maybe there is a function to do that...

For example:

FULL PATH: c:/program files/myApp/myfile.exe

I NEED: c:/program files/myApp

Thank you.

Re: How to extract a dir path from file?

Posted: Tue Dec 01, 2009 12:52 am
by FourthWorld

Code: Select all

function FilePath pFile
  set the itemdel to "/"
  delete last item of pFile
  return pFile
end FilePath

Re: How to extract a dir path from file?

Posted: Tue Dec 01, 2009 1:01 am
by ale870
I found another solution, but mine is more complex:

Code: Select all

put myFile into myDirPath
split myDirPath using "/"
put the last line of the keys of myDirPath into myLastElement
delete variable myDirPath[myLastElement]
combine myDirPath using "/"
I will use your function, thank you!

Re: How to extract a dir path from file?

Posted: Tue Dec 01, 2009 2:59 am
by Mark
Hi,

There is no need to do complicated. If you want to know in which folder your current stack resides, just do this:

Code: Select all

set the itemDel to slash
put item 1 to -2 of the effective filename of this stack into myPath
Best,

Mark