-
Notifications
You must be signed in to change notification settings - Fork 71
/
cmd.ahk
169 lines (127 loc) · 3.83 KB
/
cmd.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
158
159
160
161
162
163
164
165
166
167
168
169
/*
Func: cmd_exec
Runs command line commands in hidden command line window
Parameters:
cmd - Command
Returns:
-
Examples:
> cmd_exec(" RD /S /Q """ SourceDir """ ")
= Folder "e:\temp\myOtherFolder" and all contents including subfolders get deleted
*/
cmd_exec(cmd) {
DetectHiddenWindows, On
run %comspec% /C %cmd%,, Hide, cmdPID
WinWait, % "ahk_pid " cmdPID, , 2 ; comspec will have fully booted after 2 seconds, and will have completed its action otherwise
WinWaitClose, % "ahk_pid " cmdPID
}
/*
Func: cmd_fileCopy
Copies file using robocopy
Parameters:
SourceFile - The name of a single file
DestDir - Specifies the path to the destination directory
Returns:
-
Examples:
> cmd_fileCopy("e:\temp\myfile2.txt", "e:\temp\anotherfolder\")
= myfile2.txt gets copied from "e:\temp" into "e:\temp\anotherfolder"
*/
cmd_fileCopy(SourceFile, DestDir) {
If !fileExist(SourceFile) or !( InStr( FileExist(DestDir), "D") )
return ErrorLevel := 1
DestDir := RTrim(DestDir, "\")
SplitPath, SourceFile, SourceFileName, SourceDir
cmd_exec("robocopy """ SourceDir """ """ DestDir """ """ SourceFileName """ ")
}
/*
Func: cmd_fileMove
Moves file using robocopy
Parameters:
SourceFile - The name of a single file
DestDir - Specifies the path to the destination directory
Returns:
-
Examples:
> cmd_fileMove("e:\temp\myfile2.txt", "e:\temp\anotherfolder\")
= myfile2.txt gets moved from "e:\temp" into "e:\temp\anotherfolder"
*/
cmd_fileMove(SourceFile, DestDir) {
If !fileExist(SourceFile) or !( InStr( FileExist(DestDir), "D") )
return ErrorLevel := 1
DestDir := RTrim(DestDir, "\")
SplitPath, SourceFile, SourceFileName, SourceDir
cmd_exec("robocopy """ SourceDir """ """ DestDir """ """ SourceFileName """ /move")
}
/*
Func: cmd_fileDelete
Delete files using command line "DEL" command
Parameters:
SourceFile - The name of a single file
Returns:
-
Examples:
> cmd_fileDelete("e:\temp\myfile2.txt")
= myfile2.txt gets deleted
*/
cmd_fileDelete(SourceFile) {
If !fileExist(SourceFile)
return ErrorLevel := 1
cmd_exec("DEL /F """ SourceFile """ ")
}
/*
Func: cmd_fileCopyDir
Copies folder using robocopy
Parameters:
SourceDir - Specifies the path to the source directory
DestDir - Specifies the path to the destination directory
Returns:
-
Examples:
> cmd_fileCopyDir("e:\temp", "e:\temp\testfolder")
= Contents including subfolders of "e:\temp" get copied into "e:\temp\testfolder"
*/
cmd_fileCopyDir(SourceDir, DestDir) {
If !( InStr( FileExist(SourceDir), "D") )
return ErrorLevel := 1
SourceDir := RTrim(SourceDir, "\")
DestDir := RTrim(DestDir, "\")
cmd_exec("robocopy """ SourceDir """ """ DestDir """ /e")
}
/*
Func: cmd_fileMoveDir
Moves folder using robocopy
Parameters:
SourceDir - Specifies the path to the source directory
DestDir - Specifies the path to the destination directory
Returns:
-
Examples:
> cmd_fileMoveDir("e:\temp\myfolder", "e:\temp\myOtherFolder")
= Contents including subfolders of "e:\temp" get moved into "e:\temp\testfolder"
and "e:\temp\myfolder" gets deleted once copying is finished
*/
cmd_fileMoveDir(SourceDir, DestDir) {
If !( InStr( FileExist(SourceDir), "D") )
return ErrorLevel := 1
SourceDir := RTrim(SourceDir, "\")
DestDir := RTrim(DestDir, "\")
cmd_exec("robocopy """ SourceDir """ """ DestDir """ /e /move")
}
/*
Func: cmd_fileRemoveDir
Deletes folder and its subfolders using command line "RD" command
Parameters:
SourceDir - Specifies the path to the source directory
Returns:
-
Examples:
> cmd_fileRemoveDir("e:\temp\myOtherFolder")
= Folder "e:\temp\myOtherFolder" and all contents including subfolders get deleted
*/
cmd_fileRemoveDir(SourceDir) {
If !( InStr( FileExist(SourceDir), "D") )
return ErrorLevel := 1
SourceDir := RTrim(SourceDir, "\")
cmd_exec(" RD /S /Q """ SourceDir """ ")
}