Jump to content

Recommended Posts

Posted

As in the example, I just want to get the C:\Program Files (x86)\AutoIt3\ directory with the pattern.

and how should I do this without StringReplace($ReplaceDirInEXE, "SciTE\", "")

This code works fine for me, but the autoit directory is just an example, so I don't know what to replace SciTE \.

$dir = "C:\Program Files (x86)\AutoIt3\SciTE\SciTE.exe"
$ReplaceDirInEXE = StringRegExpReplace($dir, "[\w -.%]+(?=.exe)\.\w{2,3}", "$1")
$ReplaceDirSciTE = StringReplace($ReplaceDirInEXE, "SciTE\", "")
ConsoleWrite($ReplaceDirSciTE & @CRLF)

 

Posted (edited)

you want to get the path without the file name right ?

$dir =StringRegExpReplace($dir, "(.*)(\\.*)", "\1")

And if you need to climb an extra directory from the file name  

$dir =StringRegExpReplace($dir, "(.*)(\\.*){2}", "\1")

 

Edited by Deye
Posted

Looks a bit enormous at first glance, but I like @guinness 's solution. It covers various scenarios, including the one you are looking for.

see : https://www.autoitscript.com/forum/topic/147654-_pathsplit-with-parent-folder/

Here is the script with examples (in case the link should ever get lost ;)) :

  Reveal hidden contents

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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...