1 | #include <Date.au3> |
---|
2 | |
---|
3 | Dim $fh, $temp, $rc, $i, $stuff = "Jackdaws love my big sphinx of quartz." |
---|
4 | Dim $morestuff = "The quick brown fox jumps over the lazy dog.", $UNCpath |
---|
5 | |
---|
6 | ; Prompt for UNC path to copy test data to - must exist and be writeable |
---|
7 | |
---|
8 | $UNCpath = InputBox("Please supply a network folder name in UNC format to copy test files to", "Must exist and be writeable!", "\\<SERVER>\<SHARE>[<\PATH>]") |
---|
9 | If $UNCpath == "" and @error == 1 Then Exit |
---|
10 | If StringRight($UNCpath, 1) = "\" Then $UNCpath = StringLeft($UNCpath, Stringlen($UNCpath) - 1) |
---|
11 | |
---|
12 | ; Create folder and files for testing |
---|
13 | |
---|
14 | If Not FileExists("C:\temp") Then |
---|
15 | If Not DirCreate("C:\temp") Then |
---|
16 | ConsoleWriteError("Fatal: Failed to create folder C:\temp" & @CRLF) |
---|
17 | Exit |
---|
18 | EndIf |
---|
19 | EndIf |
---|
20 | |
---|
21 | $temp = _NowCalcDate() & _NowTime(5) |
---|
22 | $temp = StringLeft($temp, 4) & StringMid($temp, 6, 2) & StringMid($temp, 9, 4) & StringMid($temp, 14, 2) & StringRight($temp, 2) & ".$$$" |
---|
23 | If Not DirCreate("C:\Temp\" & $temp) Then |
---|
24 | ConsoleWriteError("Fatal: Failed to create C:\Temp\" & $temp & @CRLF) |
---|
25 | Exit |
---|
26 | EndIf |
---|
27 | |
---|
28 | If Not FileChangeDir("C:\Temp\" & $temp) Then |
---|
29 | ConsoleWriteError("Fatal: Failed to change dir to C:\Temp\" & $temp & @CRLF) |
---|
30 | Exit |
---|
31 | EndIf |
---|
32 | |
---|
33 | $fh = FileOpen("TestFile_1.txt", 2) |
---|
34 | If $fh == -1 Then |
---|
35 | ConsoleWriteError("Fatal: Failed to create TestFile_1.txt" & @CRLF) |
---|
36 | Exit |
---|
37 | Else |
---|
38 | For $i = 1 to 10 |
---|
39 | If Not FileWriteLine($fh, $stuff) Then |
---|
40 | ConsoleWriteError("Fatal: Failed to write data to TestFile_1.txt" & @CRLF) |
---|
41 | Exit |
---|
42 | EndIf |
---|
43 | Next |
---|
44 | FileClose($fh) |
---|
45 | EndIf |
---|
46 | |
---|
47 | $fh = FileOpen("Test File 2.txt", 2) |
---|
48 | If $fh == -1 Then |
---|
49 | ConsoleWriteError("Fatal: Failed to create Test File 2.txt" & @CRLF) |
---|
50 | Exit |
---|
51 | Else |
---|
52 | For $i = 1 to 10 |
---|
53 | If Not FileWriteLine($fh, $morestuff) Then |
---|
54 | ConsoleWriteError("Fatal: Failed to write data to Test File 2.txt" & @CRLF) |
---|
55 | Exit |
---|
56 | EndIf |
---|
57 | Next |
---|
58 | FileClose($fh) |
---|
59 | EndIf |
---|
60 | |
---|
61 | $fh = FileOpen("Test File 3.txt", 2) |
---|
62 | If $fh == -1 Then |
---|
63 | ConsoleWriteError("Fatal: Failed to create Test File 3.txt" & @CRLF) |
---|
64 | Exit |
---|
65 | Else |
---|
66 | For $i = 1 to 5 |
---|
67 | If Not FileWriteLine($fh, $stuff) Then |
---|
68 | ConsoleWriteError("Fatal: Failed to write data to Test File 3.txt" & @CRLF) |
---|
69 | Exit |
---|
70 | EndIf |
---|
71 | Next |
---|
72 | For $i = 1 to 5 |
---|
73 | If Not FileWriteLine($fh, $morestuff) Then |
---|
74 | ConsoleWriteError("Fatal: Failed to write data to Test File 3.txt" & @CRLF) |
---|
75 | Exit |
---|
76 | EndIf |
---|
77 | Next |
---|
78 | FileClose($fh) |
---|
79 | EndIf |
---|
80 | |
---|
81 | ; Do the test |
---|
82 | |
---|
83 | ; This should work |
---|
84 | |
---|
85 | If Not FileCopy("C:\Temp\" & $temp & "\TestFile_1.txt", $UNCpath) Then |
---|
86 | ConsoleWrite("Error: Failed to copy C:\Temp\" & $temp & "\TestFile_1.txt to " & $UNCpath & @CRLF) |
---|
87 | Else |
---|
88 | ConsoleWrite("Success! Copied TestFile_1.txt to " & $UNCpath & @CRLF) |
---|
89 | EndIf |
---|
90 | |
---|
91 | ; This probably won't work |
---|
92 | |
---|
93 | If Not FileCopy("C:\Temp\" & $temp & "Test File 2.txt", $UNCpath) Then |
---|
94 | ConsoleWrite("Error: Failed to copy C:\Temp\" & $temp & "\Test File 2.txt to " & $UNCpath & @CRLF) |
---|
95 | Else |
---|
96 | ConsoleWrite("Success! Copied Test File 2.txt to " & $UNCpath & @CRLF) |
---|
97 | EndIf |
---|
98 | |
---|
99 | If Not FileCopy("""C:\Temp\" & $temp & "Test File 2.txt""", $UNCpath) Then |
---|
100 | ConsoleWrite("Error: Failed to copy ""C:\Temp\" & $temp & "\Test File 2.txt"" to " & $UNCpath & @CRLF) |
---|
101 | Else |
---|
102 | ConsoleWrite("Success! Copied Test File 2.txt to " & $UNCpath & @CRLF) |
---|
103 | EndIf |
---|
104 | |
---|
105 | If Not FileCopy("""C:\Temp\" & $temp & "Test File 2.txt""", """" & $UNCpath & """") Then |
---|
106 | ConsoleWrite("Error: Failed to copy ""C:\Temp\" & $temp & "\Test File 2.txt"" to " & """" & $UNCpath & """" & @CRLF) |
---|
107 | Else |
---|
108 | ConsoleWrite("Success! Copied Test File 2.txt to " & $UNCpath & @CRLF) |
---|
109 | EndIf |
---|
110 | |
---|
111 | If Not FileCopy("C:\Temp\" & $temp & "Test File 2.txt", """" & $UNCpath & """") Then |
---|
112 | ConsoleWrite("Error: Failed to copy C:\Temp\" & $temp & "\Test File 2.txt to " & """" & $UNCpath & """" & @CRLF) |
---|
113 | Else |
---|
114 | ConsoleWrite("Success! Copied Test File 2.txt to " & $UNCpath & @CRLF) |
---|
115 | EndIf |
---|
116 | |
---|
117 | ; This should work |
---|
118 | |
---|
119 | If FileChangeDir("C:\Temp\" & $temp) Then |
---|
120 | If Not FileCopy("Test File 3.txt", $UNCpath) Then |
---|
121 | ConsoleWrite("Error: Failed to copy C:\Temp\" & $temp & "\Test File 3.txt to " & $UNCpath & @CRLF) |
---|
122 | Else |
---|
123 | ConsoleWrite("Success! Copied Test File 3.txt to " & $UNCpath & @CRLF) |
---|
124 | EndIf |
---|
125 | Else |
---|
126 | ConsoleWrite("Error: Failed to change directory to C:\Temp\" & $temp & @CRLF) |
---|
127 | EndIf |
---|
128 | |
---|
129 | ; Optionally, clean up |
---|
130 | |
---|
131 | $rc = MsgBox(36, "Tidy up test folders and files?", "Would you like to remove the test files and folder that were copied to your systems?") |
---|
132 | If $rc == 6 Then |
---|
133 | If FileExists($UNCpath & "\TestFile_1.txt") Then |
---|
134 | If Not FileDelete($UNCpath & "\TestFile_1.txt") Then |
---|
135 | ConsoleWrite("Warning: Failed to delete " & $UNCpath & "\testFile_1.txt" & @CRLF) |
---|
136 | EndIf |
---|
137 | EndIf |
---|
138 | If FileExists($UNCpath & "\Test File 2.txt") Then |
---|
139 | If Not FileDelete($UNCpath & "\Test File 2.txt") Then |
---|
140 | ConsoleWrite("Warning: Failed to delete " & $UNCpath & "\Test File 2.txt" & @CRLF) |
---|
141 | EndIf |
---|
142 | EndIf |
---|
143 | If FileExists($UNCpath & "\Test File 3.txt") Then |
---|
144 | If Not FileDelete($UNCpath & "\Test File 3.txt") Then |
---|
145 | ConsoleWrite("Warning: Failed to delete " & $UNCpath & "\Test File 3.txt" & @CRLF) |
---|
146 | EndIf |
---|
147 | EndIf |
---|
148 | If Not DirRemove("C:\temp\" & $temp, 1) Then |
---|
149 | ConsoleWrite("Warning: Failed to delete C:\temp\" & $temp & " and contents" & @CRLF) |
---|
150 | EndIf |
---|
151 | EndIf |
---|
152 | |
---|
153 | Exit |
---|