UNC Pfad/Path Validation

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

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

UNC Pfad/Path Validation

06 Sep 2020, 06:34

Hallo,
AHK's DriveGet/DriveSpaceFree sehen auch die Verwendung von UNC-/Netzwerkpfaden als Parameter vor.
Diese Option sollte nun auch Einzug halten in (m)eine Umsetzung der genannten Befehle in ein AHK object: DriveGetObj()

Hierbei ist vorgesehen drei Validierungskonditionen zu prozessieren:
a) Pfad-/Laufwerkangaben im Format C:\,C:,C als valide (hier C stellvertretend als beliebiger <Laufwerksbuchstabe>)
b) Pfad-/Laufwerkangaben im UNC-Format \\Servername\Freigabename\Pfad als valide
c) Laufwerktypangaben im Format "CDROM, REMOVABLE, FIXED, NETWORK, RAMDISK, UNKNOWN" als valide

Aktuell ist lediglich das am Start: var := StrLen(var) = 1 ? RegExReplace(var,"\W") ":\" : var (hängt, AFAIK, ein ':\' an (vermeintliche) Laufwerkbuchstaben an).

RegEx kommt bei mir bekanntlich gleich nach dem Handstand :roll:
Mit Bitte um Feedback.

Greetz,
BoBo
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: UNC Pfad/Path Validation

07 Sep 2020, 17:14

Ein bisschen regex magic

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

text =
(
d:\
C:
C
fG:
t:
t:\
rt:
rt:\
fs
f
\\Servername\Freigabename\Pfad
\\Servername\Freigabename
\\Servername\Freigabename\Pfad\Pfad\
\\Servername232\Freigabename_223\Pfad-akefh
\\++++\dfklaf
FIXED
NETWORK
NETORK
RAMDISK
RAMDISC
UNKNOWN
)

Loop, parse, text, `n`r
{
	RegExMatch(A_LoopField, "^(\w{1})(:|:\\|$)$", found)
	if found {
		MsgBox,,,Laufwerknotation %found%
	}
	
	RegExMatch(A_LoopField, "^\\\\\w*\\[(\w|\-)*\\]*", found)
	if found {
		MsgBox,,,UNC Notation %found%
	}
	
	; https://www.autohotkey.com/boards/viewtopic.php?p=110696#p110696
	RegExMatch(A_LoopField, "(CDROM|REMOVABLE|FIXED|NETWORK|RAMDISK|UNKNOWN)", found)
	if found {
		MsgBox,,,Liste %found%
	}
}

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

Re: UNC Pfad/Path Validation

08 Sep 2020, 02:59

To be reviewed. Stay tuned :mrgreen:
just me
Posts: 9563
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: UNC Pfad/Path Validation

08 Sep 2020, 04:36

Moin BoBo,

für die Laufwerkstypen ist

Code: Select all

	if var in CDROM,REMOVABLE,FIXED,NETWORK,RAMDISK,UNKNOWN
perfekt. Etwas 'modernere' Varianten wären z.B.

Code: Select all

If (Var ~= "^CDROM|REMOVABLE|FIXED|NETWORK|RAMDISK|UNKNOWN$")
   MsgBox, 0, RegEx, Bingo!
If InStr("|CDROM|REMOVABLE|FIXED|NETWORK|RAMDISK|UNKNOWN|", "|" . Var . "|")
   MsgBox, 0, InStr, Bingo!
Ich würde in diesem Fall ausschließlich die Laufwerksliste zurückgeben.

Für Laufwerke oder UNC-Pfade würde ich für die 'Validierung' schlicht FileExist(Var) verwenden. Die Laufwerke könnten vorher so 'formatiert' werden:

Code: Select all

L := StrLen(Var)
Var .= (L = 1) ? ":\" : (L = 2) ? "\" : ""

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: effel and 17 guests