-
Notifications
You must be signed in to change notification settings - Fork 71
/
CountOfFiles.ahk
54 lines (38 loc) · 1.02 KB
/
CountOfFiles.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
CountOfFiles(fnFilePattern,fnMode := "F")
{
; returns a count of all files that match the file pattern provided
; MsgBox fnFilePattern: %fnFilePattern%`nfnMode: %fnMode%
; declare local, global, static variables
Try
{
; set default return value
CountOfFiles := 0
; validate parameters
If (StrLen(fnFilePattern) = 0)
Throw, Exception("fnFilePattern was empty")
If fnMode not contains D,F,R
Throw, Exception("fnMode doesn't contain D,F,R")
; initialise variables
If !RegExMatch(fnFilePattern,"iS)^([A-Z]:|\\)\\(\w+\\)*([\w\*]+\.[\w\*]+)$")
fnFilePattern .= "\*.*"
If (fnMode = "R")
fnMode := "FR"
; count files
Loop, Files, %fnFilePattern%, %fnMode%
CountOfFiles++
}
Catch, ThrownValue
{
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return CountOfFiles
}
/* ; testing
RootPath := "C:\Test"
FileCount := CountOfFiles(RootPath,"R")
MsgBox, %RootPath% has %FileCount% files.
*/