WildByDesign Posted January 1 Posted January 1 I need help with creating a function that I can pass a path to and have it confirm whether it's the root of the drive or not. Example: $sDriveC = "C:" $sDriveD = "D:" $sDriveE = "E:" $sDriveR = "R:" $sNotRoot = "C:\Example" If IsRootDrive($sDriveC) Then ConsoleWrite("This is root drive." & @CRLF) If Not IsRootDrive($sNotRoot) Then ConsoleWrite("This is not a root drive." & @CRLF) Func IsRootDrive($sDrive) ; ; something like: ; "*:" ; needs to confirm 2 characters ; first character being a single drive letter ; second character being a colon ; there is no backslash in this situation ; ; if root drive, Return True ; if not root, Return False EndFunc I hope that I explained it well enough within the code box. I have literally zero understanding of regex. Thank you for your time.
Solution WildByDesign Posted January 1 Author Solution Posted January 1 I just noticed the _WinAPI_PathIsRoot() function which I may be able to work with. My scenario does not provide the backslash which is required to return True with the _WinAPI_PathIsRoot() function. However, I can certainly append the backslash for this purpose or even modify the _WinAPI_PathIsRoot() slightly.
MattyD Posted Friday at 01:04 AM Posted Friday at 01:04 AM PathIsRoot is probably the better solution, but just for the exercise. \A and \z matches the start and end of the string. [A-Za-z]: matches any letter and the colon \\? matches a backslash, ? means 0 or 1 times. $sDriveC = "C:" $sDriveD = "D:" $sDriveE = "E:" $sDriveR = "R:" $sNotRoot = "C:\Example" If IsRootDrive($sDriveC) Then ConsoleWrite("This is root drive." & @CRLF) If Not IsRootDrive($sNotRoot) Then ConsoleWrite("This is not a root drive." & @CRLF) Func IsRootDrive($sDrive) ; ; something like: ; "*:" ; needs to confirm 2 characters ; first character being a single drive letter ; second character being a colon ; there is no backslash in this situation ; ; if root drive, Return True ; if not root, Return False ;~ Return StringRegExp($sDrive, "\A[A-Za-z]:\\?\z") ;Optionally has backslash Return StringRegExp($sDrive, "\A[A-Za-z]:\z") EndFunc If you're interested and have the time, I believe there's a tutorial in the autoit help file on regular expressions. They can be a bit of a headache at times, but it's a powerful thing to have the kit bag WildByDesign 1
jchd Posted Saturday at 11:25 AM Posted Saturday at 11:25 AM Warning that subst-ed drives may point to non-root, soft and hard links as well. WildByDesign 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
WildByDesign Posted Saturday at 12:17 PM Author Posted Saturday at 12:17 PM On 1/1/2026 at 8:04 PM, MattyD said: If you're interested and have the time, I believe there's a tutorial in the autoit help file on regular expressions. They can be a bit of a headache at times, but it's a powerful thing to have the kit bag Thank you for the script. It always blows my mind how small the regex is. Small yet powerful. I think that you are right. I should learn at least some of the basics of regex. I don't think that I would quite need anything more advanced with it but the basics would be good to learn. I'll do some reading today. 49 minutes ago, jchd said: Warning that subst-ed drives may point to non-root, soft and hard links as well. Good point, thank you. I haven't quite gotten that far yet with the script but that is absolutely a solid point. MattyD 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now