Zipping files based on date stamp - AutoIT

RE: Question ID 26825760

billprew and TheGorby have already produced an excellent script, but I'm hoping I can get some assistance to make a few changes.

Is there a way to supress the message boxes, so I can automate & schedule this process?

Is there a way to stop the source files from being deleted?
mbsadmin2Asked:
Who is Participating?
 
TheGorbyConnect With a Mentor Commented:
Since it's easy to remove code like you're asking, I went ahead and did so.

Notes:
-The source and destination directories must already exist
-For automation you can use switches as follows: Program.exe "C:\Source" year "C:\Destination"
-If there are no archived files for a given month/year, that zip file will be deleted
-Source files won't be deleted
-If the supplied directories or year are invalid, the program displays an error and quits
-There are only 3 indications the script is running;
---the progress window still appears
---there's an icon in the systray while the program runs
---if there is an error (as mentioned above), a message displays that error but will close itself after 5 seconds
#include <Zip-v2.au3>

Dim $output=@TempDir & "\output.tmp"

If $CmdLine[0]=3 Then
	$parentfld=$CmdLine[1]
	If Not FileExists($parentfld) Then _Error(1)
	$parentfld="""" & $parentfld & """"
	$yr=$CmdLine[2]
	Select
		Case StringLen($yr)<>4
			_Error(2)
		Case $yr<1980
			_Error(2)
		Case $yr>@YEAR
			_Error(2)
	EndSelect
	$zippth=$CmdLine[3]
	If Not FileExists($zippth) Then _Error(3)
	If StringInStr($zippth,"\",0,-1)<>StringLen($zippth) Then $zippth=$zippth & "\"
Else
	Exit
EndIf

RunWait(@ComSpec & " /c DIR " & $parentfld & " /A:-D /B /S /T:W>" & $output)
$hnd=FileOpen($output,1)
FileWrite($hnd,"STOP")

ProgressOn("File Zipper","Archiving " & $yr & "...","Currently processing: ",200,200,16)
For $mo=1 To 12
	FileFlush($hnd)
	FileSetPos($hnd,0,0)
	If StringLen($mo)=1 Then $mo="0" & $mo
	ProgressSet(($mo-1)*8.33,"Currently processing: month " & $mo)
	If Not FileExists($zippth & $mo & $yr & ".zip") Then
		$zipname=_Zip_Create($zippth & $mo & $yr & ".zip")
	Else
		$zipname=$zippth & $mo & $yr & ".zip"
	EndIf
	While 1
		$line=FileReadLine($hnd)
		If $line="STOP" Then ExitLoop
		If FileExists($line) Then
			$mod=FileGetTime($line)
			If $mod[0]=$yr Then
				If $mod[1]=$mo Then $actual=_Zip_AddItem($zipname,$line,"",12)
			EndIf
		EndIf
	WEnd
	$count=_Zip_Count($zipname)
	If $count=0 Then FileDelete($zippth & $mo & $yr & ".zip")
	ProgressSet($mo*8.33,"Currently processing: month " & $mo)
Next
ProgressOff()
FileClose($hnd)
FileDelete($output)
Exit

Func _Error($code)
	Switch $code
		Case 1
			MsgBox(0+16+0+8192+262144,"Error - Invalid switch","Error - the specified source directory does not exist. Quitting...",5)
		Case 2
			MsgBox(0+16+0+8192+262144,"Error - Invalid switch","Error - the specified year is invalid or is not between 1979 and " & @YEAR+1 & ". Quitting...",5)
		Case 3
			MsgBox(0+16+0+8192+262144,"Error - Invalid switch","Error - the specified destination directory does not exist. Quitting...",5)
	EndSwitch
	Exit
EndFunc

Open in new window

0
 
TheGorbyCommented:
Do you mean to suppress ALL dialog boxes, so that the entire script runs silently, or just the message boxes, so that it requires no human interaction?
0
 
TheGorbyCommented:
Also - you'll still need to download and rename the Zip-v2.txt file as mentioned in the related question. If you already have then that same file will still work with the new script.
0
 
mbsadmin2Author Commented:
Thanks for the great responses TheGorby.  I haven't had a chance to test this yet, but I will do shortly.  I'll let you know how I go.
0
 
mbsadmin2Author Commented:
Thanks heaps, this worked well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.