Jump to content

Recommended Posts

Posted

hi guys,

I am not new to autoit but I am everything but a programmer so here is my question:

I have FileSelectFolder in a script and I want to use the folder name again later in the script but not the full path

e.g. "c:\program files\anyapps" but the folder name "anyapps".

Any idea how to do this in an easy way?

thanks, Martin

Posted

  mscrx said:

hi guys,

I am not new to autoit but I am everything but a programmer so here is my question:

I have FileSelectFolder in a script and I want to use the folder name again later in the script but not the full path

e.g. "c:\program files\anyapps" but the folder name "anyapps".

Any idea how to do this in an easy way?

thanks, Martin

$path="c:\program files\anyapps"
$FolderName=StringSplit($path,"\")
MsgBox(0,"","The name of the folder is: " & $FolderName[$FolderName[0]])
Posted (edited)

You can check out _PathSplit() in the help file, but I find it a bit overblown because you have to declare ByRef variables for parts you may not want. A simpler way is to just use this:

$sFile = StringRight($sPath, StringLen($sPath) - StringInStr($sPath, "\", 0, -1))

<_<

P.S. Didn't see Nahuel's while posting - another good possibility.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

  Nahuel said:

$path="c:\program files\anyapps"
$FolderName=StringSplit($path,"\")
MsgBox(0,"","The name of the folder is: " & $FolderName[$FolderName[0]])
That one works great!

thank you very much!

Martin

Posted

And here is fast RegExp method <_< :

$Path = "c:\program files\anyapps"
$FolderName = StringRegExpReplace($Path, "^.*\\", "")
MsgBox(0, "", "The name of the folder is: " & $FolderName)

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

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