Jump to content

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! ;)

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...