Backup - ZIP - Then email
Moderators: Dorian (MJT support), JRL
Backup - ZIP - Then email
Do you know if there is an easy way to automate a backup of certain files in a folder? What I need to do is, back up the last 31 files in a folder that have been modified by date.
All he files are named yyyymmdd.jou (year, month, day) these need to be zipped up and then emailed. Not asking too much??
Cheers in advance
All he files are named yyyymmdd.jou (year, month, day) these need to be zipped up and then emailed. Not asking too much??
Cheers in advance
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Not asking much no. We can use GetFileList to get a list of the files. Then loop through them, zip them using the zip library and email them using SMTPSendMail.
However, the devil is in the detail. Before we go writing example code for you can you explain what you mean by the last 31 files? Do you mean the NEWEST 31 files, or the OLDEST 31 files? Is it always 31 or might it vary? Please describe the criteria that determines which files should be zipped up. Then we can give you some more specific help and maybe even write some code for you.
However, the devil is in the detail. Before we go writing example code for you can you explain what you mean by the last 31 files? Do you mean the NEWEST 31 files, or the OLDEST 31 files? Is it always 31 or might it vary? Please describe the criteria that determines which files should be zipped up. Then we can give you some more specific help and maybe even write some code for you.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
So you want a script that zips up the latest 7 files in a folder, and emails that zip?
Ok. First you need to download the Zip Library from:
http://www.mjtnet.com/plugins.htm
Open up the ziplib.zip file and extract ziplib.dll and ziplib.ini into the Imports folder in your Macro Scheduler program folder. If an Imports sub folder does not exist, create one. So this Imports folder should be beneath the main Macro Scheduler 11 program folder (usually c:\program files\macro scheduler 11).
Now create a new macro and paste in the following code:
Modify the first 8 lines to suit your setup. The first is the path of the folder containing the files you want to zip up. The second is the path for the zip file you want to create/modify.
Hopefully the rest of the code is self-explanatory.
Ok. First you need to download the Zip Library from:
http://www.mjtnet.com/plugins.htm
Open up the ziplib.zip file and extract ziplib.dll and ziplib.ini into the Imports folder in your Macro Scheduler program folder. If an Imports sub folder does not exist, create one. So this Imports folder should be beneath the main Macro Scheduler 11 program folder (usually c:\program files\macro scheduler 11).
Now create a new macro and paste in the following code:
Code: Select all
//Config
Let>file_folder=c:\users\user\documents
Let>zip_file=c:\users\user\documents\zips\myzip.zip
Let>server=myserver.com
Let>[email protected]
Let>from_name=myself
Let>[email protected]
Let>subject=Here's the zip file
Let>body=See attached
//Run a DOS cmd to get list of files in folder sorted by date (oldest first - dos only does oldest first)
Let>RP_WINDOWMODE=0
Let>RP_WAIT=2
Run>cmd.exe /c dir "%file_folder%" /B /A-D /OD >> "%TEMP_DIR%\files.txt"
//Read in files
ReadFile>%TEMP_DIR%\files.txt,file_list
DeleteFile>%TEMP_DIR%\files.txt
//Separate file_list to array
Separate>file_list,CRLF,files
//We want last 7 items
Let>k=files_count-7
If>k<1
Let>k=1
Endif
//loop through and zip them up
Repeat>k
Let>this_file=files_%k%
//worth double checking file exists
IfFileExists>%file_folder%\%this_file%
ZIP_Add>%zip_file%,%file_folder%\%this_file%,9,0,r
Endif
Let>k=k+1
Until>k=files_count
//now we can email the zip file
SMTPSendMail>recipients,server,from_email,from_name,subject,body,zip_file
Hopefully the rest of the code is self-explanatory.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
hey mate - i have been trying to get this to work for me but have had no joy. I am receiving an email with no attachment - is there something I have missed? here is my code:
Code: Select all
Let>file_folder=c:\bup\
Let>zip_file=c:\zips\myzip.zip
Let>server=mail.chsglobal.com
Let>[email protected]
Let>from_name=ANZ_Backup
Let>[email protected]
Let>subject=Here's the zip file
Let>body=See attached
//Run a DOS cmd to get list of files in folder sorted by date (oldest first - dos only does oldest first)
Let>RP_WINDOWMODE=0
Let>RP_WAIT=2
Run>cmd.exe /c dir "%file_folder%" /B /A-D /OD >> "%TEMP_DIR%\files.txt"
//Read in files
ReadFile>%TEMP_DIR%\files.txt,file_list
DeleteFile>%TEMP_DIR%\files.txt
//Separate file_list to array
Separate>file_list,CRLF,files
//We want last 7 items
Let>k=files_count-7
If>k<1>k=1
Endif
//loop through and zip them up
Repeat>k
Let>this_file=files_%k%
//worth double checking file exists
IfFileExists>%file_folder%\%this_file%
ZIP_Add>%zip_file%,%file_folder%\%this_file%,9,0,r
Endif
Let>k=k+1
Until>k=files_count
//now we can email the zip file
SMTPSendMail>recipients,server,from_email,from_name,subject,body,zip_file
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Step through it in the debugger and see where it fails.
Also I suspect it's the forum that has corrupted it but your posted code has
which should be
Also I suspect it's the forum that has corrupted it but your posted code has
Code: Select all
//We want last 7 items
Let>k=files_count-7
If>k<1>k=1
Endif
Code: Select all
//We want last 7 items
Let>k=files_count-7
If>k<1
Let>k=1
Endif
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Let's start with the bleeding obvious. Did you download and install the zip library as described? To be sure: Do you see an Imports folder in c:\program files\Macro Scheduler 11 and does that Imports folder include ziplib.dll and ziplib.ini ?
Which version of Macro Scheduler are you using?
When you step through with the debugger do you see values for file_list and files in the watch list? What is the value of files_count? Do you step through the Repeat/Until and onto Zip_Add or does that bit get skipped?
C'mon - give us a small scrap to go on .... my crystal ball is out of magic dust.
Which version of Macro Scheduler are you using?
When you step through with the debugger do you see values for file_list and files in the watch list? What is the value of files_count? Do you step through the Repeat/Until and onto Zip_Add or does that bit get skipped?
C'mon - give us a small scrap to go on .... my crystal ball is out of magic dust.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?