-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathFS.ahk
157 lines (138 loc) · 7.42 KB
/
FS.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
; DOC: Determines if a file or directory exists
FS_Exists(path)
{
return FileExist(fileName) <> ""
}
; DOC: Determines if a file exists and is a file
FS_FileExists(fileName)
{
result := FileExist(fileName)
return result <> "" && InStr(result, "D") = 0
}
; DOC: Determines if a file exists and is a file
FS_IsFile(fileName)
{
return FS_FileExists(fileName)
}
; DOC: Determines if a directory exists and is a directory
FS_DirExists(dirName)
{
result := FileExist(dirName)
return result <> "" && InStr(result, "D") > 0
}
; DOC: Determines if a directory exists and is a directory
FS_DirectoryExists(dirName)
{
return FS_DirExists(dirName)
}
; DOC: Determines if a directory exists and is a directory
FS_IsDirectory(dirName)
{
return FS_DirExists(dirName)
}
; DOC: Creates a file and its parent directories if necessary
FS_FileCreate(fileName, encoding="")
{
; OutputDebug In FS_FileCreate(%fileName%, %encoding%)
if(IsEmpty(encoding))
encoding := "UTF-16"
SplitPath, fileName, fname, dir, ext, nnoext, drv
if(!FS_DirectoryExists(dir))
{
FileCreateDir, %dir%
if ErrorLevel
{
; OutputDebug Could not create directory %dir%
return false
}
}
file := FileOpen(fileName, "w", encoding)
return file
}
FS_CreateFile(fileName, encoding="")
{
return FS_FileCreate(fileName, encoding)
}
; DOC: Creates a directory and its parent directories if necessary
FS_MkDir(dirName)
{
FileCreateDir, %dirName%
if ErrorLevel
return false
else
return true
}
; DOC: Creates a directory and its parent directories if necessary
FS_DirectoryCreate(dirName)
{
return FS_MkDir(dirName)
}
; DOC: Creates a directory and its parent directories if necessary
FS_CreateDirectory(dirName)
{
return FS_MkDir(dirName)
}
; DOC: Creates a directory and its parent directories if necessary
FS_CreateDir(dirName)
{
return FS_MkDir(dirName)
}
; DOC: Creates a directory and its parent directories if necessary
FS_DirCreate(dirName)
{
return FS_MkDir(dirName)
}
FS_FileCount(pattern)
{
result := 0
Loop,%pattern%
{
result++
}
return result
}
FS_ShortcutCreate(TargetFileName, ShortcutDirectory, Description = "", recreate = false)
{
SplitPath, TargetFileName, fileName, dirName, ext, nameNoext, drive
shortcutFileName := ShortcutDirectory "\" nameNoext ".lnk"
if(FS_FileExists(shortcutFileName))
{
if(recreate)
{
FileDelete, %shortcutFileName%
FileCreateShortcut, %TargetFileName%, %shortcutFileName%, %dirName%, , %Description%, %TargetFileName%
}
}
else
{
FileCreateShortcut, %TargetFileName%, %shortcutFileName%, %dirName%, , %Description%, %TargetFileName%
; MsgBox ErrorLevel = %ErrorLevel%
}
}
FS_ShortcutRemove(TargetFileName, ShortcutDirectory, Description = "")
{
SplitPath, TargetFileName, fileName, dirName, ext, nameNoext, drive
shortcutFileName := ShortcutDirectory "\" nameNoext ".lnk"
if(FS_FileExists(shortcutFileName))
{
FileDelete, %shortcutFileName%
}
}
; DOC: Creates a startup shortcut for the specified file deleting the previous one
FS_StartupShortcutCreate(TargetFileName, Description = "", recreate = false)
{
FS_ShortcutCreate(TargetFileName, A_Startup, Description, recreate)
}
; DOC: removes a startup shortcut
FS_StartupShortcutRemove(TargetFileName, Description = "")
{
FS_ShortcutRemove(TargetFileName, A_Startup, Description = "")
}
FS_DesktopShortcutCreate(TargetFileName, Description = "", recreate = false)
{
FS_ShortcutCreate(TargetFileName, A_Desktop, Description, recreate)
}
FS_DesktopShortcutRemove(TargetFileName, Description = "")
{
FS_ShortcutRemove(TargetFileName, A_Desktop, Description = "")
}