obtain name and path

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

obtain name and path

09 Jan 2022, 16:16

I need to make a menu with ahk. I have the script to do it.

Any menu needs an ini file

of this sort or type
Spoiler

I need of a folder obtain the name of any file inside it : folder, file, shortcut, url. And the complete path or the url .
name is the title+number in the ini file
path + number is the path or the url of the element contained in the folder.

Do you know any script to do this ?
Best Regards
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: obtain name and path

09 Jan 2022, 17:28

Code: Select all

ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini"), path := {}
IniRead, titles, %ini%, Titles
IniRead, paths, %ini%, Paths
For each, line in StrSplit(titles, "`n")
 If ((part := StrSplit(line, "=")).2 > ""
  && RegExMatch(paths, "m`a)" StrReplace(part.1, "Title", "Path") "=\K.+", commandLine)
  && path[part.2] := commandLine)
   Menu, menu, Add, % part.2, Go

F3::Menu, menu, Show ; F3 = Show the menu

Go:
Run, % path[A_ThisMenuItem]
Return
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

Re: obtain name and path

10 Jan 2022, 06:41

I am running to try . Best Regards
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

Re: obtain name and path

10 Jan 2022, 06:48

Is running, but I don't see where is creating the ini file. I give the name "obtain the ini file.ahk"

I execute the script in the same folder where are the icons I try to obtain title and patch.
Best Regards
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: obtain name and path

10 Jan 2022, 06:49

It reads the INI file that you have posted. Another way is below. It gets EXE paths or whatever is specified as the target, rather than other command-line parameters. Adjust as needed.

Code: Select all

dir  := A_ScriptDir
ini  := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
n    := 0
path := {}

Loop, Files, %dir%\*.*
{ SplitPath, A_LoopFilePath,,, ext, ttitle
  Switch ext {
   Case "lnk": FileGetShortcut, %A_LoopFilePath%, commandLine
   Case "url": FileRead, ttext, %A_LoopFilePath%
               RegExMatch(ttext, "m`a)URL=\K.+", commandLine)
   Default   : Continue
  }
  n++, path[ttitle] := commandLine
  IniWrite, %ttitle%, %ini%, Titles, Title%n%
  IniWrite, %commandLine%, %ini%, Paths, Path%n%
  Menu, menu, Add, %ttitle%, Go
}

F3::Menu, menu, Show ; F3 = Show the menu

Go:
Run, % path[A_ThisMenuItem]
Return
To get arguments:

Code: Select all

Case "lnk": FileGetShortcut, %A_LoopFilePath%, target,, args
            commandLine := args > "" ? args : target
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

Re: obtain name and path

12 Jan 2022, 06:38

Thanks mikeyww. I will try my very best.

Best Regards
:superhappy:
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

Re: obtain name and path

12 Jan 2022, 17:51

But the target not is to read the ini file, only create one with the shortcuts (title and path) of any folder, url and file inside the folder.....
:roll:
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: obtain name and path

12 Jan 2022, 20:27

The pieces are here. You can use whatever parts you need.
AutoPepe
Posts: 70
Joined: 08 May 2016, 15:34

Re: obtain name and path

13 Jan 2022, 05:08

I'll try my very best.
Best Regards
:superhappy:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 361 guests