/************************************************************************************************************* This ado-file zips files. Required: File path: file paths of files to be zipped. Saving: Path of folder to contain zipped files. Options: Replace: replace existing zipped path. May specify replace either inside or outside the saving option. zipexecutable: location of 7za executable file stata: use stata unzipfile command in place of gunzipfile. Extension of file to unzip must be .zip. erase: Erase unzipped file. mac: For use on OSX. Requires installation of p7za in Terminal. Tested on OSX 10.9. Step-by-step instructions: You need to run the command in the terminal app. (Original from this website: http://superuser.com/questions/548349/how-can-i-install-7zip-so-i-can-run-it-from-terminal-on-os-x) To install p7zip using Homebrew, first update your brew formulae to be sure you are getting the latest p7zip. $ brew update Use Homebrew to install p7zip: $ brew install p7zip Add all files in the sputnik directory to the compressed file heed.7z: $ 7z a heed.7z sputnik Unzip heed.7z: $ 7z x heed.7z Written by Gabriel Chodorow-Reich and provided without any warranty This version: August 2014 *************************************************************************************************************/ capture program drop gzipfile program define gzipfile syntax anything(name=filenames id="File path"), SAVing(string asis) [replace ZIPEXEcutable(string) stata mac erase] local dir "`c(pwd)'" if `"`zipexecutable'"' != `""' { local ZipExe `"`zipexecutable'"' } else { local ZipExe `"`=regexr(`"`=c(pwd)'"',`"[Dd]ropbox.*$"',`"Dropbox"')'\7-Zip"' } tokenize `"`filenames'"' forvalues i = 1/`:word count `filenames'' { if regexm(`"``i''"',`"^([aA-zZ]:)|(/)"') | `"`stata'"'==`"stata"' { local infilenames `"`infilenames' "``i''""' } else { local infilenames `"`infilenames' "`dir'/``i''" "' } } if regexm(`"`saving'"',`",( )?(replace)$"') { local replace replace local saving = regexr(`"`saving'"',`",( )?(replace)$"',`""') } capture qui di `saving' if _rc==0 { local saving = `saving' } if regexm(`"`saving'"',`"\.[0-9a-zA-Z]+$"') { local extension = regexr(`"`saving'"',`"^.*\."',`""') } else { local extension 7z } if regexm(`"`saving'"',`"^\.\."') { local filename = regexr(`"`saving'"',`"^.*[/\\]"',`""') cd `"`=regexr(`"`saving'"',`"[/\\]`filename'.*$"',`""')'"' local saving `"`c(pwd)'/`filename'"' cd `"`dir'"' } else if !regexm(`"`saving'"',`"^(([aA-zZ]:)|(/))"') { local saving `"`dir'/`saving'"' } if `"`replace'"'==`"replace"' { local overwrite `"-y"' } if inlist(`"`c(os)'"',`"Windows"',`"Unix"') & regexm(`"`:dir `"`ZipExe'"' files *'"',`"7za"') & `"`stata'"'!=`"stata"' { di `"!cd "`ZipExe'" & 7za a -t`extension' `overwrite' "`saving'" `infilenames' "' !cd "`ZipExe'" & 7za a -t`extension' `overwrite' "`saving'" `infilenames' } else if (inlist(`"`c(os)'"',`"MacOSX"') | `"`mac'"'==`"mac"') & regexm(`"`:dir `"`ZipExe'"' files *'"',`"7za"') & `"`stata'"'!=`"stata"' { di `"shell /usr/local/bin/7za a -t`extension' `overwrite' "`saving'" `infilenames' "' shell /usr/local/bin/7za a -t`extension' `overwrite' "`saving'" `infilenames' } else { zipfile `infilenames', saving(`"`saving'"', `replace') } if `"`erase'"'!=`""' { foreach filename of local filenames { erase `"`filename'"' } } end