Sign in to follow this  
Followers 0
HockeyFan

Help with Strings

5 posts in this topic

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!


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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

You bet. Good luck with your project.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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  
Followers 0