Virtualfile question

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Virtualfile question

Post by amyren »

I have this function that should read a directory and pack all .dat files into a virtual zip file, and then upload it to my ftp server.
My resulting zip file does apear on the server, so it apear to work.

But I found there is a file named 0 that is created in the progdir every time the function runs, which is the same file as my uploaded zipfile.

Looking at my code, I found I must have made a copy/paste mistake when writing the line that defines the virtual file. (first line in the example code below) I figured I just needed to remove that part which says "statusfil$ =", but then it will not work at all.
The variable statusfil$ is used for something else another place in my script, but is unused at the time this code below is executed, so it contains Nil

What is

Code: Select all

	
		brettarkiv$ = statusfil$ = DefineVirtualFileFromString("", "bingobrett.zip", True)
		zip.OpenArchive(1, brettarkiv$,#MODE_WRITE)
		For s$ In DirectoryItems(brettmappe$)
			brettfil$ = brettmappe$.."/"..s$
			If FindStr(brettfil$, ".dat")
				zip.AddFile(1, brettfil$)
			EndIf
		Next		
		zip.CloseArchive(1)
		UploadFile(serverbrettfil$, {File = brettarkiv$})
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Virtualfile question

Post by jPV »

amyren wrote: Tue Jun 29, 2021 1:04 pm brettarkiv$ = statusfil$ = DefineVirtualFileFromString("", "bingobrett.zip", True)
Why do you have two "=" characters here? Assigning a value into a variable will give 0 as the result of the assignment operation itself always (for example, DebugPrint(a = 3) would print "0" even though "a" gets assigned with "3"). So, the result from DefineVirtualFileFromString() will be assigned into the statusfil$ variable in this case, and the result of that assignment operation (0) will be placed into the brettarkiv$ variable.

zip.OpenArchive(1, brettarkiv$,#MODE_WRITE)
So, here brettarkiv$ is assigned with the value "0" and a new zip archive is created to a file named "0". All further file operations are made into this "0" file and the virtual file isn't used at all.

brettfil$ = brettmappe$.."/"..s$
Small tip, if you would use FullPath(brettmappe$, s$) then you don't have to handle the "/" manually and it's safer if your path happens to have / in it already.

If FindStr(brettfil$, ".dat")
This will take other than .dat files too, you'll have to do:
If FindStr(brettfil$, ".dat") > -1
or
If EndsWith(brettfil$, ".dat")


But about the main question... I'm not sure if virtual files can be used with the Zip plugin at all... you might need to use a temporary file for that.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Virtualfile question

Post by amyren »

jPV wrote: Tue Jun 29, 2021 3:26 pm Why do you have two "=" characters here?
It should not be there. That was why I wrote that I have done a copy/paste mistake without noticing.
But it does not work if I remove it, which might support your comment that zip files does not go with virtual files.

And thanks for your useful tips also.
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Virtualfile question

Post by airsoftsoftwair »

jPV wrote: Tue Jun 29, 2021 3:26 pm But about the main question... I'm not sure if virtual files can be used with the Zip plugin at all... you might need to use a temporary file for that.
Actually, virtual files should be working with zip.OpenArchive().
Post Reply