-
Notifications
You must be signed in to change notification settings - Fork 72
/
DriveGetLabels.ahk
64 lines (49 loc) · 1.66 KB
/
DriveGetLabels.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
DriveGetLabels(fnDrivesList)
{
; creates an array for each attached drive to store the label of that drive
; MsgBox fnDrivesList: %fnDrivesList%
; declare local, global, static variables
Global DriveLabelA, DriveLabelB, DriveLabelC, DriveLabelD, DriveLabelE, DriveLabelF, DriveLabelG, DriveLabelH, DriveLabelI, DriveLabelJ, DriveLabelK, DriveLabelL, DriveLabelM, DriveLabelN, DriveLabelO, DriveLabelP, DriveLabelQ, DriveLabelR, DriveLabelS, DriveLabelT, DriveLabelU, DriveLabelV, DriveLabelW, DriveLabelX, DriveLabelY, DriveLabelZ
Try
{
; set default return value
ReturnValue := 0 ; success
; validate parameters
AlphabetCSV := "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
DrivesList := ""
FailedValidation := 0
Loop, Parse, fnDrivesList
If A_LoopField in %AlphabetCSV%
DrivesList .= A_LoopField
If !DrivesList
Throw, Exception("No valid drives found in fnDrivesList")
; initialise variables
; create array
Loop, Parse, DrivesList
{
ThisDriveLetter := A_LoopField
Try ; allow for unlabeled drives
{
DriveGet, ThisDriveLabel, Label, %ThisDriveLetter%:
DriveLabel%ThisDriveLetter% := ThisDriveLabel
}
}
}
Catch, ThrownValue
{
ReturnValue := !ReturnValue
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return ReturnValue
}
/* ; testing
DrivesList := "CD"
ReturnValue := DriveGetLabels(DrivesList)
DrivesList := "DE"
ReturnValue := DriveGetLabels(DrivesList)
MsgBox, % "DriveGetLabels`n`nReturnValue: " ReturnValue "`n`nDriveLabelC: " DriveLabelC "`nDriveLabelD: " DriveLabelD "`nDriveLabelE: " DriveLabelE
*/