Jump to content
Sign in to follow this  
Crazyglew

Small question

Recommended Posts

Crazyglew

I'm pretty new to AutoIt, so forgive me if this has been covered or is in the wrong forum, but I can't find it. :D

How can I edit a path that I have received in a variable? I created a browse button that will look for an excel file, and I want to filter out just the file name from the path:

EX. path = c:\folder\FileName.xls

I would like to extract the FileName.xls part to add to a variable for use later on in the script.

(And the c:\folder\ part will not always be the same path)

Any help is appreciated.

Thanks!

Share this post


Link to post
Share on other sites
covaks

Here's two different ways you might try:

$path = "c:\folder\FileName.xls"
$path = StringRight($path,StringLen($path)-StringInStr($path,"\",0,-1))
msgbox(1,"",$path)

; A second way, maybe easier to understand
$path = "c:\folder\FileName.xls"
$path = StringSplit($path,"\")
msgbox(1,"",$path[$path[0]])

Share this post


Link to post
Share on other sites
Crazyglew

Here's two different ways you might try:

$path = "c:\folder\FileName.xls"
$path = StringRight($path,StringLen($path)-StringInStr($path,"\",0,-1))
msgbox(1,"",$path)

; A second way, maybe easier to understand
$path = "c:\folder\FileName.xls"
$path = StringSplit($path,"\")
msgbox(1,"",$path[$path[0]])
That's EXCELLENT. Exactly what I was looking for. Thank You! :D

Share this post


Link to post
Share on other sites
redsleeves

You may also want to check out the _PathSplit function.

From the help file:

#include <file.au3>
Dim $szDrive, $szDir, $szFName, $szExt
_PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt)
MsgBox(0,"_PathSplit",$szFName& $szExt)

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  

×