6
$\begingroup$

Mathematica has the handy CreateArchive function, which allows you to efficiently create a TAR archive from a directory. However, I see no way of specifying not to include the directory itself, so that the files in it are included directly in the top-level of the TAR.

Note that:

  • I am looking for a cross-platform solution (i.e. running a command on the underlying OS is not an option).

  • I am dealing with large files, so I am looking for fast low-level copying (i.e. importing the files and then exporting them again would work, but very slowly).

  • I understand having all the files in the top-level directory is not the best practice, but this needs to be the case for compatibility purposes (i.e. to comply with a file-format specification).

Any ideas or suggestions?

Thanks!

$\endgroup$
  • $\begingroup$ I tried, but could not find a way. There does not seem to be an option for this. This seems to be a limitation in create archive. You could always edit the zip file and delete the top folder. Some tools exist for this if you google around. Or you can just call the system zip command from inside Mathematica to do this bypassing CreateArchive $\endgroup$ – Nasser Nov 30 '17 at 4:20
  • $\begingroup$ There probably is a way to do that with JLink` , I'm not experienced enough to confirm though. $\endgroup$ – Kuba Nov 30 '17 at 7:46
  • $\begingroup$ I agree with Kuba that doing this via JLink` the most promissing way. If you want to avoid needing and deploying an extra java library with your package you can use the /SystemFiles/Converters/Java/tar.jar that Mathematica comes with (and most probably is what CreateArchive is based on). That seems to be version 2.3 of the com.ice.tar package for which you can find some information and documentation in the web... $\endgroup$ – Albert Retey Nov 30 '17 at 10:08
  • $\begingroup$ Unfortunately it's not possible to control the root structure in existing versions. This will likely be updated in the future, but not this upcoming version. $\endgroup$ – GenericAccountName Jan 30 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.