SplitPathObj() - SplitPath on Steroids

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

SplitPathObj() - SplitPath on Steroids

05 Jun 2020, 07:32

Wurde :arrow: hier nachgefragt.
(M)eine zweifelsohne noch eindampfbare Version ... (fängt schon damit an :arrow: spth.fnm/spth.dir/spth.ext/spth.noe/spth.drv :shh:)
Archiv
... Zugang nur für Gelangweilte. Die IMHO bessere Lösung bereits im folgenden Beitrag/Senf von @just me. Kudos! :thumbup:
Um just me's Beitrag die entsprechende Würdigung zuteil werden zu lassen, erlaubte ich mir den Titel des Threads entsprechend anzupassen. Merci.
just me
Posts: 9509
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SplitPath, ... über ein Array abfragen.

06 Jun 2020, 05:48

Moin BoBo,

gute Idee!

Ich vermeide aber die Verwendung von globalen Variablen in Funktionen wann immer ohne größeren Aufwand möglich.
Deshalb mein Senf:

Code: Select all

#NoEnv
SPO := SplitPathObj(A_WorkingDir "\" A_ScriptName)
MsgBox % "Dir: " . SPO.Dir . "`nFileName: " . SPO.FileName ; Ausgabe der Arraywerte
ExitApp

; ======================================================================================================================
; Funktion SplitPathObj()
; Ersatz für das AHK-eigene SplitPath-Kommando.
; Die Funktion erstellt ein Array mit den Schlüsseln
;     "FileName"
;     "Dir"
;     "Extension"
;     "NameNoExt"
;     "Drive"
; und den Werten der entsprechenden Augabevariablen des SplitPath-Kommandos.
; ======================================================================================================================
SplitPathObj(Path2Split) {
   Local
   ; Zerlegung des Pfades mittels AHK Standard-Kommando
	SplitPath, Path2Split, Nam, Dir, Ext, NNE, Drv
   ; Assoziatives Array erstellen und zurückgeben
   Return {FileName: Nam, Dir: Dir, Extension: Ext, NameNoExt: NNE, Drive: Drv}
}
; ======================================================================================================================
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: SplitPathObj() - SplitPath on Steroids

21 Jun 2020, 17:03

Hallo @BoBo, @just me, kudos! Darf ich Folgendes im englischsprachigen Forum posten?

EDIT: Ach, ist schon da!

Code: Select all

; By just me
; See https://www.autohotkey.com/boards/viewtopic.php?f=10&t=76920
; per inspiration from Bobo

#NoEnv
SPO := SplitPathObj(A_WorkingDir "\" A_ScriptName)
MsgBox % "Dir: " . SPO.Dir . "`nFileName: " . SPO.FileName "`nExtension: " . SPO.Extension . "`nName (no extension): " . SPO.NameNoExt . "`nDrive: " . SPO.Drive ; Array value output.
ExitApp

; ======================================================================================================================
; Function SplitPathObj()
; Replacement for the AHK standard SplitPath command
; The function creates an array with the keys:
;     "FileName"
;     "Dir"
;     "Extension"
;     "NameNoExt"
;     "Drive"
; and values corresponding to the output variables of the SplitPath command.
; ======================================================================================================================
SplitPathObj(Path2Split) {
   Local
   ; Unbundle the path using the standard AHK command.
	SplitPath, Path2Split, Nam, Dir, Ext, NNE, Drv
   ; Create and return an associative array.
   Return {FileName: Nam, Dir: Dir, Extension: Ext, NameNoExt: NNE, Drive: Drv}
}
; ======================================================================================================================
Grüße,
burque505

Return to “Skripte und Funktionen”

Who is online

Users browsing this forum: No registered users and 9 guests