-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathFGP.ahk
111 lines (103 loc) · 3.13 KB
/
FGP.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* FGP_Init()
* Gets an object containing all of the property numbers that have corresponding names.
* Used to initialize the other functions.
* Returns
* An object with the following format:
* PropTable.Name["PropName"] := PropNum
* PropTable.Num[PropNum] := "PropName"
*/
FGP_Init() {
static PropTable
if (!PropTable) {
PropTable := {Name: {}, Num: {}}, Gap := 0
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(0)
while (Gap < 11)
if (PropName := oFolder.GetDetailsOf(0, A_Index - 1)) {
PropTable.Name[PropName] := A_Index - 1
PropTable.Num[A_Index - 1] := PropName
Gap := 0
}
else
Gap++
}
return PropTable
}
/* FGP_List(FilePath)
* Gets all of a file's non-blank properties.
* Parameters
* FilePath - The full path of a file.
* Returns
* An object with the following format:
* PropList.CSV := "PropNum,PropName,PropVal`r`n..."
* PropList.Name["PropName"] := PropVal
* PropList.Num[PropNum] := PropVal
*/
FGP_List(FilePath) {
static PropTable := FGP_Init()
SplitPath, FilePath, FileName, DirPath
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(DirPath)
oFolderItem := oFolder.ParseName(FileName)
PropList := {CSV: "", Name: {}, Num: {}}
for PropNum, PropName in PropTable.Num
if (PropVal := oFolder.GetDetailsOf(oFolderItem, PropNum)) {
PropList.Num[PropNum] := PropVal
PropList.Name[PropName] := PropVal
PropList.CSV .= PropNum "," PropName "," PropVal "`r`n"
}
PropList.CSV := RTrim(PropList.CSV, "`r`n")
return PropList
}
/* FGP_Name(PropNum)
* Gets a property name based on the property number.
* Parameters
* PropNum - The property number.
* Returns
* If succesful the file property name is returned. Otherwise:
* -1 - The property number does not have an associated name.
*/
FGP_Name(PropNum) {
static PropTable := FGP_Init()
if (PropTable.Num[PropNum] != "")
return PropTable.Num[PropNum]
return -1
}
/* FGP_Num(PropName)
* Gets a property number based on the property name.
* Parameters
* PropName - The property name.
* Returns
* If succesful the file property number is returned. Otherwise:
* -1 - The property name does not have an associated number.
*/
FGP_Num(PropName) {
static PropTable := FGP_Init()
if (PropTable.Name[PropName] != "")
return PropTable.Name[PropName]
return -1
}
/* FGP_Value(FilePath, Property)
* Gets a file property value.
* Parameters
* FilePath - The full path of a file.
* Property - Either the name or number of a property.
* Returns
* If succesful the file property value is returned. Otherwise:
* 0 - The property is blank.
* -1 - The property name or number is not valid.
*/
FGP_Value(FilePath, Property) {
static PropTable := FGP_Init()
if ((PropNum := PropTable.Name[Property] != "" ? PropTable.Name[Property]
: PropTable.Num[Property] ? Property : "") != "") {
SplitPath, FilePath, FileName, DirPath
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(DirPath)
oFolderItem := oFolder.ParseName(FileName)
if (PropVal := oFolder.GetDetailsOf(oFolderItem, PropNum))
return PropVal
return 0
}
return -1
}