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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Utilities

From novice to tech pro — start learning today.