Page 1 of 1 1
Topic Options
#194205 - 2009-06-10 04:09 PM String manipulation
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Hi,

How do I strip a filename from a path to just leave me the the base folder?

Eg if I have:

c:\document and settings\users\test.txt

strip the path out to give:

c:\document and settings\users\

Thanks in advance.

Darren
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#194206 - 2009-06-10 04:23 PM Re: String manipulation [Re: Darren_W]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
You could always split and rejoin.

 Code:
$file = "c:\document and settings\users\test.txt"
$array = split($file,"\")

for $x = 0 to ubound($array) -1
     $path = $path + $array[$x] + "\"
next

? $path

Top
#194207 - 2009-06-10 04:28 PM Re: String manipulation [Re: eriqjaffe]
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Yep that does the trick, thanks for that...

Darren
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#194210 - 2009-06-10 05:11 PM Re: String manipulation [Re: Darren_W]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You don't actually need the loop:
 Code:
$file = "c:\document and settings\users\test.txt"
$array = split($file,"\")


$path=Join($array,"\",UBound($array))+"\"

$path+@CRLF

Top
#194213 - 2009-06-10 05:35 PM Re: String manipulation [Re: Richard H.]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
The PathSplit UDF returns a 4 element array with the server name (if share), share name or drive letter, folder path, and file name items.

It's posted here, and the latest is on my web site in the Resources section.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.052 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org