How to extract a dir path from file?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

How to extract a dir path from file?

Post by ale870 » Tue Dec 01, 2009 12:34 am

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.
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to extract a dir path from file?

Post by FourthWorld » Tue Dec 01, 2009 12:52 am

Code: Select all

function FilePath pFile
  set the itemdel to "/"
  delete last item of pFile
  return pFile
end FilePath
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to extract a dir path from file?

Post by ale870 » Tue Dec 01, 2009 1:01 am

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!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to extract a dir path from file?

Post by Mark » Tue Dec 01, 2009 2:59 am

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply