LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding a folder to a zip file

How can I add a folder to a zip file. What I want is to create a txt file, which I place in a regular folder,  then place the regular folder in a zipped folder. They all (folder, file , and zip) need to be the same name also, so the directory would be as an example C:\Desktop > runner.zip > runner > runner.txt or something similar. So far I can create a zip file, and I can create a regular folder and place the txt document in the regular folder, but i cannot seem to be able to put the regular folder in the zip folder. I get an error saying: "LabVIEW:  An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @." It creates the zip file, and also the other folder with the txt file in it, but it wont put the regular folder in the zip file.

Thanks ahead of time

0 Kudos
Message 1 of 16
(6,959 Views)

The "source file path" input into the zip-file VI should be the full path to the file, the "destination path in zip" should be the relative path for that file within the zip file, so a path equivalent to runner\runner.txt

You could either make this manually in a string and use string->path, or use a combination of strip path, build path and string to path to work it out automatically from the file output when you define the file to zip.

 

There's a fully fledged example at labview\examples\file\Zip Tool.llb

 

or the block diagram below might help

zip-with-folder.png

Normal warning: This is not set up to prevent overwriting existing files.

0 Kudos
Message 2 of 16
(6,943 Views)

I have been messing with this code and it gives me the same thing. It just gives a zip file with the text file inside of it. I need a text file inside of a folder inside of zip file

0 Kudos
Message 3 of 16
(6,931 Views)

@lvuser333 wrote:

I have been messing with this code and it gives me the same thing. It just gives a zip file with the text file inside of it. I need a text file inside of a

folder inside of zip file


It's working for me.

 

Is the file you want to zip in a folder with the name you want (in the zip file) already?

 

0 Kudos
Message 4 of 16
(6,927 Views)

are you using the example file or the same code as the above screen shot? So i think my problem is I have been trying to addd the folder to a zip file I created, whereas I think that if I just zip up the folder that has the txt file in it, I will then have a zip file which contains a folder which contains the txt file, is this correct?

0 Kudos
Message 5 of 16
(6,916 Views)

@lvuser333 wrote:

are you using the example file or the same code as the above screen shot? So i think my problem is I have been trying to addd the folder to a zip file I created, whereas I think that if I just zip up the folder that has the txt file in it, I will then have a zip file which contains a folder which contains the txt file, is this correct?


I'm using the code in the screenshot (I whipped up the example quickly to see if I could get it to work, so it probably isn't the best or cleanest way to do it).

[The example code from NI should work, but is probably more than you need].

 

 

You zip files, but you tell the VI which folder within the zip file (i.e. relative to the zip file) you want them to go in.

Just like how you might have a folder tree on your C drive

 

animals

->mammals

---->four_legs

-------->delicious

-------->thinks_you_are_delicious

---->two_legs

->birds

---->can_fly

---->cannot_fly

->fish

---->salt_water

---->fresh_water

 

You can have the same structure in the zip file.

For instance a photo of a flathead (a type of salt water fish)..

the file might be flathead.jpg with the path within the zip would be fish\salt_water\flathead.png

on the other hand a tiger photo

the file would be tiger.png but the path would be mammals\four_legs\thinks_you_are_delicious\tiger.png

 

 

0 Kudos
Message 6 of 16
(6,909 Views)


@Hornless.Rhino wrote:

the file might be flathead.jpg with the path within the zip would be fish\salt_water\flathead.png


of course both of those should have had the same extension 🙂

0 Kudos
Message 7 of 16
(6,900 Views)

i think I tried everything that you guys said but I still cannot seem to get it. I tried the original screenshot you posted but I want to create the files also and not have the user pick them. I attached a code i wrote up, i am getting duplicate path name errors and also when I run the code (depending on how I wire it) i can get a folder, text file, and zip file, but they are not all within eachother.

0 Kudos
Message 8 of 16
(6,874 Views)

"You zip files, but you tell the VI which folder within the zip file (i.e. relative to the zip file) you want them to go in.

Just like how you might have a folder tree on your C drive"

 

- i understand that you zip files, but how can i tell the vi which folder within the zip file to go into if I cannot put any files in my zip file in the first place??

0 Kudos
Message 9 of 16
(6,873 Views)

You have a problem when you are moving your text file.  Your destination path should include the file itself, not just the folder to put it in.  Use the same constant that you are using for the add to zip file's source path.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 16
(6,863 Views)