Jump to content
Sign in to follow this  
HockeyFan

Help with Strings

Recommended Posts

I need to pull the file name out of a files full path, for example:

I would like to pull "Firefox Setup 4.0.exe" from the this path: C:\Software\Firefox v4\Firefox Setup 4.0.exe

I've played around with this, but I'm not getting the results that I expected. :huh2:

$Path = "C:\Software\Firefox v4\Firefox Setup 4.0.exe"
$String = StringRight($Path, StringInStr($Path, "\", 0, -1)) 
MsgBox(0,"File name: ", $String)

What's the best way to perform this even if the path was "C:\Firefox Setup 4.0.exe"?

Thanks! ;)

Share this post


Link to post
Share on other sites

Try with this UDF, _PathSplit. Good luck!

Thank you!!! :huh2:

That UDF works perfectly. Thanks for the pointer!!

$Path = "C:\Software\Firefox v4\Firefox Setup 4.0.exe"
$PathArray = _PathSplit($Path, $szDrive, $szDir, $szFName, $szExt) 
MsgBox(0,"File name: ", $PathArray[3] & $PathArray[4])

Share this post


Link to post
Share on other sites

An alternate solution:

$sPath = "C:\Software\Firefox v4\Firefox Setup 4.0.exe"
$aSplit = StringSplit($sPath, "\")
$sFileName = $aSplit[1] & "\" & $aSplit[$aSplit[0]]

Edit: Missed the front of the path.

Edited by GMK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...