Zlib and Minizip - How to add a new directory to a .zip file - c++

I have written an application to compress the contents of directory to a .zip file from C++, using zlib and minizip. Minizip is not well documented online but the file "zip.h" in the source code contains comments.
My application uses FindFirstFile and FindNextFile to get a list of all files (and subfolders) in the directory and then, as shown here How do I use Minizip (on Zlib)? creates a .zip file and opens new files within the .zip.
Then I read the source files with fopen and fread and write the contents to the newly created files in the .zip folder. This all works just fine if the directory to be compressed contains only files, and no subfolders, but I cannot decipher from the comments in the source code how I add a new folder to a .zip file and then write files to that folder.

As it turns out, you don't need to create a new directory in the .zip file as a separate step. You can just pass the parameter "foldername\filename.ext" to the zipOpenNewFileInZip method and it will create the "foldername" directory for you then add a new file "filename.ext" to that directory.

Related

Proper way to zip xlsx-file from directory using Info-Zip's Zip utility

I’m using Zip utility from the Info-Zip library to compress the tree of catalogs to get xlsx-file.
For that I’m using the next command:
zip -r -D res.xlsx source
source - contains the correct directory tree of the xlsx file.
But if you then look at the resulting file structure, the source directory will be included in the paths of all files and directories at the top level, and MS Office Excel will not be able to open this file. This is a well known problem. To avoid it zip.exe needs to be inside of the dest directory.
The problem is that I want to use the source code of this utility in my project, so this leads me to be unable to call my process, which will be responsible for compressing directories, to get xlsx files from these directories.
I’ve tried to find a place in the zip source code, where the parent catalog appending on the top-level happens. But seems
it is done implicitly.
Who can suggest how it can be done?

Apple script to move files of a type

I have a folder of approximately 1800~ .7z files. Some of them uncompress as a single file, some uncompress as a folder with several of the same type of file. If I were to uncompress all of them at the same time, what I end up with is a folder full of .7z files, folders containing multiple of a file type, and multiple single instances of that same file type.
What I would like to do is run a script that would take all of the same file types, from all containing folders below the main folder, and copy them to another specified folder. I unfortunately don't have really any experience with Apple Scripts and while this may be simple, it sounds insurmountable to me. Any input would be appreciated.

Adding a CSV file to a project in Visual Studio

I am working on a project where I have to read in serveral pre-existing CSV (dog.csv, horse.csv, etc.). I want to know how would I add these file into my project so that I may test to see if my print functions work (the code is written in c++). Would I have to copy and paste the files into the debugging folder or would I place it under the test folder of the project?
You can include the files in your project in whatever (sub)folder you wish by using Right click -> Add -> Existing Item. Then, right-click on each file and choose Properties. Set up "Copy to output directory" to "Copy if newer".
Then after build, your files will be copied into the bin/debug folder.
To read the file, you can just use:
System.IO.File.ReadAllText("dog.csv");
Another possible way is to add a file within project, right click and select properties, and then in Copy to Output Directory, select Copy always. This way, csv file will be automatically copied in your debug and release packages too.
string executableLocation = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
string csvLocation= Path.Combine(executableLocation, "file.csv");
Above code will read file location from bin directory where your csv file will be stored.
This link should help guide you how to add CSV files to a project.
If you wanted to do a down and dirty way you could just save the CSV's somewhere on your local machine, and then hard code the file path to that location.
Example:
c:\test\Dog.csv and then set that as a variable for whenever you need to read in the csv file.

Open a zip file and move the file in another zip in c++?

I wanted to open a zip file (mod.zip) and move the file inside, to another zip file (minecraft.zip) and owerwrite the file with same names.I hope you understand because im not english.
I dont know if i can open zip files or i need libraries
I would recommend 7zip SDK, it lets you zip and unzip things in .7z and .zip and many other formats

Scons: How to add a target for creating a zip file that contains source files?

Say I have a couple of source files (e.g.foo.c, foo.h, bar.c, bar.h, baz.c, baz.h). I want to bundle them together by making a zip file that contains those files by simply typing scons zip. In addition, those files have to be inside a src/ directory in the zip file.
How should I proceed? I've looked at the Mkdir(), Copy() etc. commands in the Scons user manual, but I have no idea how to bundle them together in a single target.
Here's a very simple SConstruct to do what you want. You'll have to modify it for your real source layout and you probably don't want to create a src/ directory at the root of your project.
# list of source, header files
files = ['foo.h', 'foo.c', 'bar.h', 'bar.c', 'baz.h', 'baz.c']
# create the directory structure for the zip file
pkg_files = Install('src', files)
# create the zip file
z = Zip('pkg.zip', pkg_files)
Alias('zip', z)
You can find more information about the Zip Builder on the SCons man page.