-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDir.ahk
37 lines (35 loc) · 939 Bytes
/
Dir.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
/*
Extended library for Directory functions.
(c) 2022-2024 Ken Verdadero
2022-07-23
*/
/**
* Lists all files in a directory.
*
* Similar to Python's os.listdir.
* Add 'R' in mode to list recursively.
*
* @param directory
* @param {String} filePattern
* @param {String} mode
* @param {String} exclude
* @returns {Array} array of file list
*/
DirList(directory, filePattern := '*.*', mode := 'DF', exclude := '') {
if Type(directory) != "String" {
throw TypeError("Expected a String type, got " Type(directory))
}
if !RegExMatch(DirExist(directory), 'D') {
throw ValueError("Not a valid directory", , directory)
}
list := []
loop files directory '\' filePattern, mode {
if StrLen(exclude) {
if A_LoopFileAttrib ~= Format("[{1}]", exclude) {
continue
}
}
list.Push(A_LoopFileFullPath)
}
return list
}