Search This Blog

Thursday, July 24, 2008

Archiver – Archive out older files by modified date.

This script was created with a purpose of archiving old files from one location to another.

To use, select the date of files to be archived, files on or before that day will be affected.
Type the source folder, all files within the source will be affected. Folder structure will remain.
Select whether to copy, or move the files.
Select whether to create shortcuts to the moved files in the source folder.
There is also an undo function that will put files back based on the log.

Please let me know if there are any bugs in it.



  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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=archiver2.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
	Archiver.
		Alex Belenkiy - ab@nyitsupport.com
		07/24/2008

		This script was created with a purpose of archiving old files from one location to another.

		To use, select the date of files to be archived, files on or before that day will be affected.
		Type the source folder, all files within the source will be affected. Folder structure will remain.
		Select whether to copy, or move the files.
		Select whether to create shortcuts to the moved files in the source folder.
		There is also an undo function that will put files back based on the log.

		RecursiveFileSearch function was modified from http://www.autoitscript.com/forum/index.php?showtopic=58558&st=0
#ce

#include <array.au3>
#include <file.au3>
#include <GUIConstants.au3>

AutoItSetOption("TrayIconHide", 1)
dim $LogArray
dim $jobRunning = "0"
dim $PreSetDate = @YEAR & @MON & @MDAY
dim $errorSet = "0"
dim $fileMove, $Array, $copyMove, $destFolder, $fileMove, $FilePathSplit, $NewDestFolder, $oldFile, $OldFolder, $OldPathSplit
dim $FileTotalSize, $fileSize
dim $FileModDate
dim $UNC

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=\\SRV1\ab\my documents\dev\nyitsupport\archiver\frmarchiver.kxf
$frmArchiver = GUICreate("Archiver", 395, 243, 343, 243)
GUISetOnEvent($GUI_EVENT_CLOSE, "frmArchiverClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "frmArchiverMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "frmArchiverMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "frmArchiverRestore")
$lblDate = GUICtrlCreateLabel("Select files modified on or before:", 8, 8, 176, 21, 0x01)
$Date1 = GUICtrlCreateDate("", 192, 8, 194, 21,0x00010000)
GUICtrlSetOnEvent(-1, "Date1Change")
$btnSource = GUICtrlCreateButton("Source Folder", 8, 40, 97, 21, 0)
GUICtrlSetOnEvent(-1, "btnSourceClick")
$btnDest = GUICtrlCreateButton("Destination Folder", 8, 70, 97, 21, 0)
GUICtrlSetOnEvent(-1, "btnDestClick")
$radMove = GUICtrlCreateRadio("Move", 8, 104, 65, 25)
GUICtrlSetOnEvent(-1, "radMoveClick")
$radCopy = GUICtrlCreateRadio("Copy", 72, 104, 65, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetOnEvent(-1, "radCopyClick")
$chkShortcuts = GUICtrlCreateCheckbox("Create Shortcuts In Source Folder", 144, 104, 241, 25)
GUICtrlSetOnEvent(-1, "chkShortcutsClick")
GUICtrlSetState(-1, $GUI_DISABLE)
$btnOK = GUICtrlCreateButton("OK", 40, 136, 148, 49)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "btnOKClick")
$btnUndo = GUICtrlCreateButton("Undo", 216, 136, 140, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "btnUndoClick")
$txtSource = GUICtrlCreateInput("", 112, 40, 273, 21)
$txtDest = GUICtrlCreateInput("", 112, 70, 273, 21)
$lblStatus = GUICtrlCreateLabel("", 8, 192, 380, 25, 0x01)
$lblCredits1 = GUICtrlCreateLabel("Alex Belenkiy", 8, 224, 76, 17)
GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
$lblCredits2 = GUICtrlCreateLabel("ab@nyitsupport.com", 277, 224, 108, 17)
GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008080)
GUICtrlSetState($btnOK, $GUI_DISABLE)
GUICtrlSetState($btnDest, $GUI_DISABLE)
GUICtrlSetState($txtSource, $GUI_DISABLE)
GUICtrlSetState($txtDest, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


GuiCtrlSendMsg($Date1, 0x1032, 0, "yyyyMMdd")
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd


While 1
	Sleep(100)
WEnd

Func btnOKClick()
	$FileTotalSize = 0
	$fileSize = 0
	$PreSetDate = GUICtrlRead($Date1)
	$sourceFolder = GUICtrlRead($txtSource)
	$destFolder = GUICtrlRead($txtDest)
	if GUICtrlRead($radCopy) = $GUI_CHECKED then $copyMove = "Copy"
	if GUICtrlRead($radMove) = $GUI_CHECKED then $copyMove = "Move"
	if GUICtrlRead($chkShortcuts) = $GUI_CHECKED then
		$shortCut = "yes"
	Else
		$shortCut = "no"
	EndIf
	$jobRunning = "1"
	GUICtrlSetState($txtSource, $GUI_DISABLE)
	GUICtrlSetState($btnSource, $GUI_DISABLE)
	GUICtrlSetState($btnDest, $GUI_DISABLE)
	GUICtrlSetState($btnOK, $GUI_DISABLE)
	GUICtrlSetState($btnUndo, $GUI_DISABLE)
	GUICtrlSetState($Date1, $GUI_DISABLE)
	GUICtrlSetState($frmArchiver, $GUI_DISABLE)
	GUICtrlSetState($radCopy, $GUI_DISABLE)
	GUICtrlSetState($radMove, $GUI_DISABLE)
	GUICtrlSetState($chkShortcuts, $GUI_DISABLE)
	GUICtrlSetData($lblStatus, "Please wait for the operation to complete.")
	If StringRight($sourceFolder, 1) <> "\" Then $sourceFolder &= "\"
	If StringRight($destFolder, 1) <> "\" Then $destFolder &= "\"
	$logFile = FileOpen ("Archiver - " & $CopyMove & " - " & @MON & "-" & @MDAY & "-" & @YEAR & " - " & @HOUR & "-" & @MIN & ".csv",9)
	FileWriteLine ($logFile, "Operation,Shortcut Created,Date,Time,File Size,File Modified Date,Source Folder,Source File,Destination Folder")
	$Array = RecursiveFileSearch($sourceFolder)
	For $a = 1 To $Array[0]
		$NewDestFolder = $destFolder
		$FilePathSplit = StringSplit($Array[$a], "\")
		if StringInStr($Array[$a], "\\") <> 0 then $UNC = 4
		if StringInStr($Array[$a], ":") <> 0 then $UNC = 2
		for $b = $UNC to $FilePathSplit[0] - 1
			$NewDestFolder = $NewDestFolder & $FilePathSplit[$b] & "\"
		Next
		$oldFile = $FilePathSplit[$FilePathSplit[0]]

		$OldPathSplit = StringSplit($Array[$a], "\")
		$OldFolder = StringLeft($Array[$a], StringLen($Array[$a]) - StringLen($OldPathSplit[$OldPathSplit[0]]))
		$FileTotalSize = $FileTotalSize + $fileSize
		$fileSize = FileGetSize ($Array[$a])
		$FileModDate = StringLeft (FileGetTime ($array[$a], 0,1), 8)
		if $copyMove = "Move" Then $fileMove = FileMove($Array[$a], $NewDestFolder , 9)
		if $copyMove = "Copy" Then $fileMove = FileCopy($Array[$a], $NewDestFolder , 9)
		if $fileMove = 1 then FileWriteLine ($logFile, $CopyMove & "," & $ShortCut & "," & @MON & "/" & @MDAY & "/" & @YEAR & "," & @HOUR & ":" & @MIN & ":" & @SEC & "," & $fileSize & "," & $FileModDate & "," & $OldFolder & "," & $oldFile & "," & $NewDestFolder)
		if $ShortCut = "yes" then FileCreateShortcut($NewDestFolder & $oldFile, $OldFolder & $oldFile, $NewDestFolder, "", "Link to file that was moved by ARCHIVER")
		GUICtrlSetData($lblStatus, "Processing " & $a & " / " & $array[0] & @crlf & $array[$a])
	Next
	FileWriteLine($logFile, "-------")
	FileWriteLine($logFile, "Number of files:" & $Array[0])
	FileWriteLine($logFile, "Total size of files: " & Round($FileTotalSize / 1048576, 3) & " MB" & " / " & Round($FileTotalSize / 1073741824, 3) & " GB" )
	FileClose($logFile)
	$jobRunning = "0"
	GUICtrlSetState($btnSource, $GUI_ENABLE)
	GUICtrlSetState($btnDest, $GUI_ENABLE)
	GUICtrlSetState($btnOK, $GUI_ENABLE)
	GUICtrlSetState($btnUndo, $GUI_ENABLE)
	GUICtrlSetState($Date1, $GUI_ENABLE)
	GUICtrlSetState($frmArchiver, $GUI_ENABLE)
	GUICtrlSetState($radCopy, $GUI_ENABLE)
	GUICtrlSetState($radMove, $GUI_ENABLE)
	if GUICtrlRead($radMove) = $GUI_CHECKED Then GUICtrlSetState($chkShortcuts, $GUI_ENABLE)
	GUICtrlSetData($lblStatus, "")
	MsgBox(0, "Job Complete", "Number of files:" & $Array[0] & @CRLF & "Total size:" & @CRLF & Round($FileTotalSize / 1048576, 3) & " MB" & @CRLF & Round($FileTotalSize / 1073741824, 3) & " GB")
EndFunc

Func btnUndoClick()
	dim $undoCount
	$logPath = FileOpenDialog("Select log file with undo information", @WorkingDir, "(*.csv)", 1)
	if not @error Then
		$UndoLog = FileOpen ("Archiver - UNDO - " & @MON & "-" & @MDAY & "-" & @YEAR & " - " & @HOUR & "-" & @MIN & ".csv",9)
		FileWriteLine ($UndoLog, "Status,Archived Folder,Archived File,Restore Folder")
		$jobRunning = "1"
		GUICtrlSetState($btnSource, $GUI_DISABLE)
		GUICtrlSetState($btnDest, $GUI_DISABLE)
		GUICtrlSetState($btnOK, $GUI_DISABLE)
		GUICtrlSetState($btnUndo, $GUI_DISABLE)
		GUICtrlSetState($Date1, $GUI_DISABLE)
		GUICtrlSetState($frmArchiver, $GUI_DISABLE)
		GUICtrlSetState($radCopy, $GUI_DISABLE)
		GUICtrlSetState($radMove, $GUI_DISABLE)
		GUICtrlSetState($chkShortcuts, $GUI_DISABLE)
		$logFile = FileOpen($logPath,0)
		$undoCount = _FileCountLines($logPath)
		dim $undoArray[$undoCount]
		_FileReadToArray($logPath, $undoArray)
		for $a = 2 to $undoArray[0] - 3
			if $undoArray[$a] = "-------" then ExitLoop
			$uSplit = StringSplit($undoArray[$a], ",") ;Operation[1],Shortcut Created[2],Date[3],Time[4],File Size[5],File Date[6],Source Folder[7],Source File[8],Destination Folder[9]
			if FileExists($uSplit[7] & $uSplit[8]) Then
				$fileSizeSource = FileGetSize($uSplit[9] & $uSplit[8]) ; archive location
				$fileSizeDest = FileGetSize($uSplit[7] & $uSplit[8]) ; original location
				$fileModSource = StringLeft(FileGetTime($uSplit[9] & $uSplit[8], 0, 1),8)
				$fileModDest = StringLeft(FileGetTime($uSplit[7] & $uSplit[8],0,1),8)
				$replace = MsgBox(36, "File Exists", "Would you like to replace the existing file?" & @CRLF & $uSplit[7] & $uSplit[8] & @CRLF & "Size: " & $fileSizeDest & @CRLF & "Date: " & $fileModDest & @CRLF & @crlf & "With archived file?" & @CRLF & "Size: " & $fileSizeSource & @CRLF & "Date: " & $fileModSource & @CRLF & @crlf & "Will skip the file in 30 seconds", 30)
				if $replace = 6 Then
					$fileDelete = FileMove($uSplit[9] & $uSplit[8], $uSplit[7],9)
					if $fileDelete = 1 then
						if $uSplit[2] = "yes" then FileDelete($uSplit[7] & $uSplit & ".lnk")
						FileWriteLine($UndoLog, "Success - Replaced existing file" & "," & $uSplit[9] & "," & $uSplit[8] & "," & $uSplit[7])
					Else
						FileWriteLine($UndoLog, "Failed - Could not replace existing file" & "," & $uSplit[9] & "," & $uSplit[8] & "," & $uSplit[7])
					EndIf
				Else
					FileWriteLine($UndoLog, "Failed - Existing file replace prompt declined or timed out" & "," & $uSplit[9] & "," & $uSplit[8] & "," & $uSplit[7])
				EndIf
			Else
				$filedelete = FileMove($uSplit[9] & $uSplit[8], $uSplit[7],9)
				if $fileDelete = 1 Then
					if $uSplit[2] = "yes" then FileDelete($uSplit[7] & $uSplit[8] & ".lnk")
					FileWriteLine($UndoLog, "Success - Replaced moved file" & "," & $uSplit[9] & "," & $uSplit[8] & "," & $uSplit[7])
				Else
					FileWriteLine($UndoLog, "Failed - Could not replace moved file" & "," & $uSplit[9] & "," & $uSplit[8] & "," & $uSplit[7])
				EndIf
			EndIf
			GUICtrlSetData($lblStatus, "Processing " & $a & " / " & $undoArray[0] - 4 & @CRLF & $uSplit[7] & $uSplit[8])
		Next
		FileClose($UndoLog)
		$jobRunning = "0"
		GUICtrlSetState($btnSource, $GUI_ENABLE)
		GUICtrlSetState($btnDest, $GUI_ENABLE)
		GUICtrlSetState($btnOK, $GUI_ENABLE)
		GUICtrlSetState($btnUndo, $GUI_ENABLE)
		GUICtrlSetState($Date1, $GUI_ENABLE)
		GUICtrlSetState($frmArchiver, $GUI_ENABLE)
		GUICtrlSetState($radCopy, $GUI_ENABLE)
		GUICtrlSetState($radMove, $GUI_ENABLE)
		if GUICtrlRead($radMove) = $GUI_CHECKED Then GUICtrlSetState($chkShortcuts, $GUI_ENABLE)
		GUICtrlSetData($lblStatus, "")
		MsgBox(0, "Undo Completed", "Completed " & $undoArray[0] - 4 & " Files." & @CRLF & "Please check the UNDO log file for any errors.")
	EndIf
EndFunc

Func chkShortcutsClick()

EndFunc

Func Date1Change()

EndFunc

Func frmArchiverClose()
	if $jobRunning <> "1" then Exit
EndFunc

Func frmArchiverMaximize()

EndFunc

Func frmArchiverMinimize()

EndFunc

Func frmArchiverRestore()

EndFunc

Func radCopyClick()
	GUICtrlSetState($chkShortcuts, $GUI_DISABLE)
	GUICtrlSetState($chkShortcuts, $GUI_UNCHECKED)
EndFunc

Func radMoveClick()
	GUICtrlSetState($chkShortcuts, $GUI_ENABLE)
	GUICtrlSetState($chkShortcuts, $GUI_CHECKED)
EndFunc

Func btnDestClick()
	$destFolder = FileSelectFolder("Destination Folder", "",5)
	if not @error then
		$c = StringSplit($destFolder,"\")
		if not @error Then
			GUICtrlSetState($btnOK, $GUI_ENABLE)
			GUICtrlSetData($txtDest, $destFolder)
		EndIf
	EndIf
EndFunc

Func btnSourceClick()
	GUICtrlSetState($btnDest, $GUI_DISABLE)
	$sourceFolder = FileSelectFolder("Source Folder", "",4)
	if not @error then
		$c = StringSplit($sourceFolder,"\")
		if not @error Then
			GUICtrlSetState($btnDest, $GUI_ENABLE)
			GUICtrlSetData($txtSource, $sourceFolder)
		EndIf
	EndIf
EndFunc

Func RecursiveFileSearch($RFSstartDir, $RFSpattern = ".", $RFSdepth = 0)

    ;Ensure starting folder has a trailing slash
    If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"

    If $RFSdepth = 0 Then
        ;Get count of all files in subfolders for initial array definition
        $RFSfilecount = DirGetSize($RFSstartDir, 1)
        Global $RFSarray[$RFSfilecount[1] + 1]
    EndIf

    $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
    If @error Then Return

    ;Search through all files and folders in directory
    While 1
        $RFSnext = FileFindNextFile($RFSsearch)
        If @error Then ExitLoop

        ;If folder, recurse
        If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then
            RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSpattern, $RFSdepth + 1)
        Else
            If StringRegExp($RFSnext, $RFSpattern, 0) Then
                ;Append filename to array
				$FileDate = StringLeft (FileGetTime ($RFSstartDir & "\" & $RFSnext, 0,1), 8)
				if $FileDate <= $PreSetDate Then
					$RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
					$RFSarray[0] += 1
				EndIf
                ;Increment filecount

            EndIf
        EndIf
    WEnd
    FileClose($RFSsearch)

    If $RFSdepth = 0 Then
        Redim $RFSarray[$RFSarray[0] + 1]
        Return $RFSarray
    EndIf
EndFunc   ;==>RecursiveFileSearch

The script requires a form file frmArchiver.kxf to be included with the following text. Adjust the above code location referrence:

  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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?xml version="1.0" encoding="windows-1251"?>
<object type="TAForm" name="frmArchiver">
	<properties>
		<property name="Left" vt="Int16">342</property>
		<property name="Top" vt="Int16">242</property>
		<property name="Width" vt="Int16">402</property>
		<property name="Height" vt="Int16">269</property>
		<property name="Caption" vt="String">Archiver</property>
		<property name="Color" vt="Ident">clBtnFace</property>
		<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
		<property name="Font.Color" vt="Ident">clWindowText</property>
		<property name="Font.Height" vt="Int8">-11</property>
		<property name="Font.Name" vt="String">MS Sans Serif</property>
		<property name="Font.Style" vt="Set"/>
		<property name="OldCreateOrder" vt="True">True</property>
		<property name="Visible" vt="True">True</property>
		<property name="Style" vt="Int32">-1798701056</property>
		<property name="ExStyle" vt="Int16">256</property>
		<property name="Version" vt="String">1.03</property>
		<property name="FormOptOnEvent" vt="True">True</property>
		<property name="FormOptPopulate" vt="True">True</property>
		<property name="FormOptIndentCount" vt="Int8">0</property>
		<property name="PixelsPerInch" vt="Int8">96</property>
		<property name="TextHeight" vt="Int8">13</property>
	</properties>
	<components>
		<object type="TADate" name="Date1">
			<properties>
				<property name="Left" vt="Int16">192</property>
				<property name="Top" vt="Int8">8</property>
				<property name="Width" vt="Int16">194</property>
				<property name="Height" vt="Int8">21</property>
				<property name="Date" vt="String">7/14/2008</property>
				<property name="Time" vt="String">5:59:24 PM</property>
				<property name="TabOrder" vt="Int8">0</property>
				<property name="CtrlStyle" vt="Int32">1342242816</property>
				<property name="CtrlExStyle" vt="Int16">512</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TALabel" name="lblDate">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int8">8</property>
				<property name="Width" vt="Int16">176</property>
				<property name="Height" vt="Int8">21</property>
				<property name="AutoSize" vt="False">False</property>
				<property name="Caption" vt="String">Select files modified on or before:</property>
				<property name="TabOrder" vt="Int8">12</property>
				<property name="HaveVariable" vt="False">False</property>
				<property name="CtrlStyle" vt="Int32">1342177536</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set"/>
			</properties>
			<components/>
		</object>
		<object type="TARadio" name="radMove">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int8">104</property>
				<property name="Width" vt="Int8">65</property>
				<property name="Height" vt="Int8">25</property>
				<property name="Caption" vt="String">Move</property>
				<property name="TabOrder" vt="Int8">3</property>
				<property name="CtrlStyle" vt="Int32">1342242825</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TARadio" name="radCopy">
			<properties>
				<property name="Left" vt="Int8">72</property>
				<property name="Top" vt="Int8">104</property>
				<property name="Width" vt="Int8">65</property>
				<property name="Height" vt="Int8">25</property>
				<property name="Caption" vt="String">Copy</property>
				<property name="Checked" vt="True">True</property>
				<property name="TabOrder" vt="Int8">4</property>
				<property name="TabStop" vt="True">True</property>
				<property name="CtrlStyle" vt="Int32">1342242825</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TACheckbox" name="chkShortcuts">
			<properties>
				<property name="Left" vt="Int16">144</property>
				<property name="Top" vt="Int8">104</property>
				<property name="Width" vt="Int16">241</property>
				<property name="Height" vt="Int8">25</property>
				<property name="Caption" vt="String">Create Shortcuts In Source Folder</property>
				<property name="Enabled" vt="False">False</property>
				<property name="TabOrder" vt="Int8">5</property>
				<property name="CtrlStyle" vt="Int32">1342242819</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TAButton" name="btnOK">
			<properties>
				<property name="Left" vt="Int8">40</property>
				<property name="Top" vt="Int16">136</property>
				<property name="Width" vt="Int16">148</property>
				<property name="Height" vt="Int8">49</property>
				<property name="Caption" vt="String">OK</property>
				<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
				<property name="Font.Color" vt="Ident">clWindowText</property>
				<property name="Font.Height" vt="Int8">-19</property>
				<property name="Font.Name" vt="String">MS Sans Serif</property>
				<property name="Font.Style" vt="Set">fsBold</property>
				<property name="ParentFont" vt="False">False</property>
				<property name="TabOrder" vt="Int8">6</property>
				<property name="CtrlStyle" vt="Int32">1342242816</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockWidth, DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TAButton" name="btnUndo">
			<properties>
				<property name="Left" vt="Int16">216</property>
				<property name="Top" vt="Int16">136</property>
				<property name="Width" vt="Int16">140</property>
				<property name="Height" vt="Int8">49</property>
				<property name="Caption" vt="String">Undo</property>
				<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
				<property name="Font.Color" vt="Ident">clWindowText</property>
				<property name="Font.Height" vt="Int8">-19</property>
				<property name="Font.Name" vt="String">MS Sans Serif</property>
				<property name="Font.Style" vt="Set"/>
				<property name="ParentFont" vt="False">False</property>
				<property name="TabOrder" vt="Int8">7</property>
				<property name="CtrlStyle" vt="Int32">1342242816</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockWidth, DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TAInput" name="txtSource">
			<properties>
				<property name="Left" vt="Int8">112</property>
				<property name="Top" vt="Int8">40</property>
				<property name="Width" vt="Int16">273</property>
				<property name="Height" vt="Int8">21</property>
				<property name="Enabled" vt="False">False</property>
				<property name="TabOrder" vt="Int8">8</property>
				<property name="CtrlStyle" vt="Int32">1342242944</property>
				<property name="CtrlExStyle" vt="Int16">512</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TAInput" name="txtDest">
			<properties>
				<property name="Left" vt="Int8">112</property>
				<property name="Top" vt="Int8">70</property>
				<property name="Width" vt="Int16">273</property>
				<property name="Height" vt="Int8">21</property>
				<property name="Enabled" vt="False">False</property>
				<property name="TabOrder" vt="Int8">9</property>
				<property name="CtrlStyle" vt="Int32">1342242944</property>
				<property name="CtrlExStyle" vt="Int16">512</property>
				<property name="Resizing" vt="Set">DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TALabel" name="lblStatus">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int16">192</property>
				<property name="Width" vt="Int16">380</property>
				<property name="Height" vt="Int8">25</property>
				<property name="AutoSize" vt="False">False</property>
				<property name="Caption" vt="String">Archiver Ready</property>
				<property name="Color" vt="Ident">cl3DLight</property>
				<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
				<property name="Font.Color" vt="Ident">clRed</property>
				<property name="Font.Height" vt="Int8">-16</property>
				<property name="Font.Name" vt="String">MS Sans Serif</property>
				<property name="Font.Style" vt="Set"/>
				<property name="ParentColor" vt="False">False</property>
				<property name="ParentFont" vt="False">False</property>
				<property name="TabOrder" vt="Int8">10</property>
				<property name="HaveVariable" vt="False">False</property>
				<property name="CtrlStyle" vt="Int32">1342177537</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set"/>
			</properties>
			<components/>
		</object>
		<object type="TALabel" name="lblCredits1">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int16">224</property>
				<property name="Width" vt="Int8">76</property>
				<property name="Height" vt="Int8">17</property>
				<property name="AutoSize" vt="False">False</property>
				<property name="Caption" vt="String">Alex Belenkiy</property>
				<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
				<property name="Font.Color" vt="Ident">clTeal</property>
				<property name="Font.Height" vt="Int8">-8</property>
				<property name="Font.Name" vt="String">MS Sans Serif</property>
				<property name="Font.Style" vt="Set"/>
				<property name="ParentFont" vt="False">False</property>
				<property name="TabOrder" vt="Int8">11</property>
				<property name="HaveVariable" vt="False">False</property>
				<property name="CtrlStyle" vt="Int32">1342177536</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set"/>
			</properties>
			<components/>
		</object>
		<object type="TAButton" name="btnSource">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int8">40</property>
				<property name="Width" vt="Int8">97</property>
				<property name="Height" vt="Int8">21</property>
				<property name="Caption" vt="String">Source Folder</property>
				<property name="TabOrder" vt="Int8">1</property>
				<property name="CtrlStyle" vt="Int32">1342259200</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockWidth, DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TAButton" name="btnDest">
			<properties>
				<property name="Left" vt="Int8">8</property>
				<property name="Top" vt="Int8">70</property>
				<property name="Width" vt="Int8">97</property>
				<property name="Height" vt="Int8">21</property>
				<property name="Caption" vt="String">Destination Folder</property>
				<property name="TabOrder" vt="Int8">2</property>
				<property name="CtrlStyle" vt="Int32">1342259200</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set">DockWidth, DockHeight</property>
			</properties>
			<components/>
		</object>
		<object type="TALabel" name="lblCredits2">
			<properties>
				<property name="Left" vt="Int16">277</property>
				<property name="Top" vt="Int16">224</property>
				<property name="Width" vt="Int8">108</property>
				<property name="Height" vt="Int8">17</property>
				<property name="AutoSize" vt="False">False</property>
				<property name="Caption" vt="String">ab@nyitsupport.com</property>
				<property name="Font.Charset" vt="Ident">DEFAULT_CHARSET</property>
				<property name="Font.Color" vt="Ident">clTeal</property>
				<property name="Font.Height" vt="Int8">-8</property>
				<property name="Font.Name" vt="String">MS Sans Serif</property>
				<property name="Font.Style" vt="Set"/>
				<property name="ParentFont" vt="False">False</property>
				<property name="TabOrder" vt="Int8">13</property>
				<property name="HaveVariable" vt="False">False</property>
				<property name="CtrlStyle" vt="Int32">1342177536</property>
				<property name="CtrlExStyle" vt="Int8">0</property>
				<property name="Resizing" vt="Set"/>
			</properties>
			<components/>
		</object>
	</components>
</object>










Monday, July 7, 2008

TrainSignal Training Screwup.

My company recently purchased a $19,000 complete training set from TrainSignal with a full site license.

While the material is good, it only works when launched from a locally attached drive or local copy.

If you try to run the software from a UNC path \\server\trainsignal all items give an error.

Turned out that they were using a file called proxy.exe made by northwind renamed to whatever the media html file that needed to be executed. Under each media cd folder there was an fscommand folder with batch files and exe files of the same name(exe files were renamed proxy.exe files). The batch files contained the following command:

start ../4b/4b.html

Batch files cannot be executed properly from unc paths as they assume c:\windows as the working folder. So instead of launching \\server\share\4b\4b.html it executes c:\4b\4b.html which does not exist.

Some of the material used ftoolapp.exe to launch things with the same result.

This is all due to using Flash based menus instead of something that actually works properly outside of the browser world.

We were also able to integrate this into IIS by creating a link to the UNC path. Making a virtual directory will not help as when the menu.exe files are executed in IE, they execute from %username%\temporary internet files instead of the intended location.

Lesson to be learned: write your application for the intended platform to be used. Not just make it look nice using Flash. Testing different scenarios is not a bad idea either.

The script has a few different functions:

/change

runs through all subfolders of the execution location, so you would place the exe into the root of all the training material. Renames the existing .exe files that have a corresponding .bat name to .old

Also finds any ftoolapp.exe files, renames them to .old and makes a copy of itself instead.

/undo

Performs the same function as /change, except backwards. Deletes the new .exe files and renames the .old files to .exe

no switch

This is the intended mode for the batch file problem.

Checks its own name and finds the corresponding batch file. Reads the contents of the batch file and strips start ../ from the command. Executes the command as stated using the current unc or local path.

filename.xxx as a switch

This switch was made after i discovered another problem with some of the newer training material. It was launched using ftoolapp.exe filename.xxx, which exhibited the same problem with UNC.

If the operating system is Vista, checks for the presense of the TechSmith codec in the registry and checks the file extension for .wmv or .avi and Starts Windows Media Player %programfiles%\Windows Media Player\wmplayer.exe with the corresponding media file name. Other extensions launch using the associated application.

If the OS is Windows XP, executes whatever the associated media player file is.

I ran into problems on Vista trying to launch associated WMP files, WMP comes up empty and does not play. XP did not exhibit this problem.

Please dont use the old script i posted earlier. I found yet another glitch that needed changing. Here is the new one.

  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
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=UltraProxy.ico
#AutoIt3Wrapper_outfile=UltraProxy.exe
#AutoIt3Wrapper_compression=4
#AutoIt3Wrapper_useansi=y
#AutoIt3Wrapper_run_tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
	;	----------------------------------------------------------------------------
	;	Functions:
	;		No switch execution
	;			This is the intended use of the script.
	;			Checks its own name and finds a corresponding batch file.
	;			Reads the contents of the batch file and strips “start ../” from the command.
	;			Executes the command without using the Windows command interpreter.
	;		filename.xxx
	;			This mode will start a Windows Media file that is specified.
	;
	;		/change
	;			Will check current folder and all subfolders for presence of batch files.
	;			If a batch file is found and it is not autorun.bat, the corresponding .exe file will be renamed to .old and the script will make a copy of itself in place of the .exe file.
	;
	;		/undo
	;			Will check the current folder and all subfolders for the presence of batch files.
	;			If a batch file is found and it has a corresponding .old file, the .exe will be deleted and the .old renamed to .exe.
	;
	;	----------------------------------------------------------------------------
	;	This script was made with a specific purpose of replacing the proxy.exe files used by TrainSignal training material
	;	The renamed proxy.exe files would launch name.bat files which would not work over a UNC path.(\\blah\...)
	;	This script will check it's name at startup, check the corresponding .bat file for the content,
	;	strip the bat command and use the left over command to do a clean launch. Example: "start ../intro/intro.html will become \\ProperUNCPath/intro/intro.html
	;	It is written with the specific spacing used in the TrainSignal application. Do not use it for anything else.
	;
	;	Feel free to modify at will.
	;	Alex Belenkiy © ab@nyitsupport.com
	;	07/07/2008
	;
	;	RecursiveFileSearch function was modified from http://www.autoitscript.com/forum/index.php?showtopic=58558&st=0
#ce

AutoItSetOption("TrayIconHide", 1)
AutoItSetOption("WinTitleMatchMode", 2)

#include <array.au3>

If $CmdLine[0] = 0 Then
	Call("UltraProxy")
Else
	Select
		Case $CmdLine[1] = "/undo"
			$Undo = "1"
			Call("Change")
			
		Case $CmdLine[1] = "/change"
			$Undo = "0"
			Call("Change")
			
		Case Else
			Call("ftoolapp")
	EndSelect
EndIf

Func ftoolapp()
	If @OSVersion = "WIN_VISTA" Then
		If StringRight($CmdLineRaw, 4) = ".wmv" Or StringRight($CmdLineRaw, 4) = ".avi" Then
			If FileExists(@ScriptDir & "\Codec") Then
				$TSCC = RegEnumKey("HKEY_CURRENT_USER\Software\TechSmith", 1)
				If @error Then ShellExecuteWait(@ScriptDir & "\Codec\tscc.exe")
			EndIf
			ShellExecute(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe", StringReplace(@ScriptDir & "\" & $CmdLineRaw, "/", "\", 0, 0))
		Else
			ShellExecute(StringReplace($CmdLineRaw, "/", "\", 0, 0), "", @ScriptDir)
		EndIf
	Else
		ShellExecute(StringReplace($CmdLineRaw, "/", "\", 0, 0), "", @ScriptDir)
	EndIf
EndFunc   ;==>ftoolapp

Func UltraProxy()
	$SP = StringTrimRight(@ScriptName, 4) & ".bat" ; Get launched name
	$BatchFile = FileOpen($SP, 0) ; Open corresponding batch file
	If $BatchFile = -1 Then Exit
	$SPL = FileReadLine($BatchFile, 1) ; Read the batch file command, first line only
	$new = StringReplace(StringTrimRight(@ScriptDir, 9) & StringTrimLeft($SPL, 9), "/", "\", 0, 0) ; trim off fscommand from the \\ProperUNCPath\ and 'start ../ from the batch command
	If @OSVersion = "WIN_VISTA" Then
		If StringRight($new, 4) = ".wmv" Or StringRight($new, 3) = ".avi" Then
			If FileExists(@ScriptDir & "\Codec") Then
				$TSCC = RegEnumKey("HKEY_CURRENT_USER\Software\TechSmith", 1)
				If @error Then ShellExecuteWait(@ScriptDir & "\Codec\tscc.exe")
			EndIf
			ShellExecute(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe", $new)
		Else
			ShellExecute($new, "", @ScriptDir)
		EndIf
	Else
		Run(@ComSpec & " /c Start " & StringReplace($new, "/", "\", 0, 0), @ScriptDir, @SW_HIDE) ; Change all / to \ and run the necessary file.
	EndIf
EndFunc   ;==>UltraProxy

Func Change()
	MsgBox(64, "UltraProxy", "Converting Files. May take a few minutes." & @CRLF & @CRLF & "You will be notified upon completion" & @CRLF & @CRLF & "Please Wait...", 5)
	
	Dim $RFSarray[10240]
	Dim $Increment
	$Increment = 0
	$Array = RecursiveFileSearch(@ScriptDir)
	For $a = 1 To $Array[0]
		$ExeFile = StringTrimRight($Array[$a], 4) ;File name without extension
		Select
			Case $Undo = "0"
				;if $ExeFile = "ftoolapp" then

				If Not FileExists($ExeFile & ".old") Then
					If StringRight($ExeFile, 7) = "autorun" Then
						;do nothing
					Else
						FileMove($ExeFile & ".exe", $ExeFile & ".old")
						FileCopy(@AutoItExe, $ExeFile & ".exe")
						$Increment += 1
					EndIf
				EndIf
			Case $Undo = "1"
				If FileExists($ExeFile & ".old") Then
					FileDelete($ExeFile & ".exe")
					FileMove($ExeFile & ".old", $ExeFile & ".exe")
					$Increment += 1
				EndIf
		EndSelect
	Next
	MsgBox(64, "UltraProxy", "Finished." & @CRLF & @CRLF & $Increment & " out of " & $Array[0] & " files were processed.", 10)
EndFunc   ;==>Change

Func RecursiveFileSearch($startDir, $depth = 0)
	If $depth = 0 Then Global $RFSarray[1]
	$search = FileFindFirstFile($startDir & "\*.*")
	If @error Then Return
	;Search through all files and folders in directory
	While 1
		$next = FileFindNextFile($search)
		If @error Then ExitLoop
		;If folder, recurse
		If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then
			RecursiveFileSearch($startDir & "\" & $next, $depth + 1)
		Else
			If StringInStr($startDir & "\" & $next, ".bat") Then
				_ArrayAdd($RFSarray, $startDir & "\" & $next)
				$RFSarray[0] += 1
			ElseIf StringInStr($startDir & "\" & $next, "ftoolapp.exe") Then
				_ArrayAdd($RFSarray, $startDir & "\" & $next)
				$RFSarray[0] += 1
			EndIf

		EndIf
	WEnd
	FileClose($search)
	If $depth = 0 Then Return $RFSarray
EndFunc   ;==>RecursiveFileSearch