Jump to content

Recommended Posts

Posted

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

Posted

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])
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

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
×
×
  • Create New...