-
Notifications
You must be signed in to change notification settings - Fork 72
/
CreateFolderFromString.ahk
83 lines (63 loc) · 2.02 KB
/
CreateFolderFromString.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
CreateFolderFromString(fnPathString,fnOpenFolderWindow := 0)
{
; creates a new folder from the input string
; MsgBox fnPathString: %fnPathString%`nfnOpenFolderWindow: %fnOpenFolderWindow%
; declare local, global, static variables
Global LocalSourceControlRootFolder
Try
{
; set default return value
ReturnValue := 0 ; success
; validate parameters
If !fnPathString
Throw, Exception("fnPathString was empty")
If !RegExMatch(fnPathString,"imS)([A-Z]?[:\\]\\).*") ; network share (\\abc) or drive (D:\abc)
Throw, Exception("fnPathString was not valid")
; initialise variables
PathString := fnPathString
; clean up the path string
StringReplace, PathString, PathString, $, %LocalSourceControlRootFolder%
StringReplace, PathString, PathString, /, \, All
; get the folder path
SplitPath, PathString, PathFileName, PathDir, PathExtension, PathNameNoExt, PathDrive
If !PathExtension ; if extension is empty, it's a folder path
PathDir = %PathDir%\%PathFileName% ; add the name to the folder path
; create the folder
ReturnValue := -1
IfNotExist, %PathDir%
{
InputBox, CreatePathString, %ApplicationName%, Create this folder?:,,700,150,,,,,%PathDir%
If ErrorLevel
Return ReturnValue
FileCreateDir, %PathDir%
ReturnValue := 0
Sleep, 100 ; slight delay for creation to complete
}
; open the folder
If fnOpenFolderWindow
{
IfWinNotExist, ahk_class CabinetWClass, %PathDir%
Run, %PathDir%
WinActivate, ahk_class CabinetWClass, %PathDir%
WinWaitActive, ahk_class CabinetWClass, %PathDir%
Send !d ; select address bar
}
; Clipboard := PathDir
}
Catch, ThrownValue
{
ReturnValue := !ReturnValue
CatchHandler(A_ThisFunc,ThrownValue.Message,ThrownValue.What,ThrownValue.Extra,ThrownValue.File,ThrownValue.Line,0,0,0)
}
Finally
{
}
; return
Return ReturnValue
}
/* ; testing
SomeNewFolder := "C:\abc"
ReturnValue := CreateFolderFromString(SomeNewFolder,1)
MsgBox, CreateFolderFromString`n`nReturnValue: %ReturnValue%
FileRemoveDir, %SomeNewFolder%
*/