Darren_W
(Hey THIS is FUN)
2009-06-10 04:09 PM
String manipulation

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


eriqjaffe
(Hey THIS is FUN)
2009-06-10 04:23 PM
Re: String manipulation

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


Darren_W
(Hey THIS is FUN)
2009-06-10 04:28 PM
Re: String manipulation

Yep that does the trick, thanks for that...

Darren


Richard H.Administrator
(KiX Supporter)
2009-06-10 05:11 PM
Re: String manipulation

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


Glenn BarnasAdministrator
(KiX Supporter)
2009-06-10 05:35 PM
Re: String manipulation

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