# How to zip a folder? [duplicate]

This straightforward approach doesn't seem to work:

In[42]:= cmd = StringSplit@"zip -r ~/data.zip ~/test/*"
In[43]:= RunProcess@cmd


• Try the less straightforward approach that doesn't assume zip will do wildcard expansion, which is the job of the shell... this is nothing to do with Mathematica, it seems to me. Jan 18, 2016 at 23:35
• Are you aware of CreateArchive? Jan 19, 2016 at 0:54
• But this command works in the terminal @OleksandrR.
– M.R.
Jan 19, 2016 at 0:55
• @Pickett Forgot that one, yup that solves it. But it would be nice to understand why this command that works in the shell won't work when invoked with RunProcess. If you post this as an answer I'll accept.
– M.R.
Jan 19, 2016 at 0:57
• @M.R. what do you expect? The purpose of "the terminal" is to run a shell. Try execing zip directly from C and see if it works--I bet it won't. Jan 19, 2016 at 1:25

Since Mathematica 8.0 we are in luck and there is a command called CreateArchive that can do this for us. Documentation: CreateArchive.