Page 1 of 1
revZip - Create new Archive questions
Posted: Sun Aug 04, 2013 5:10 pm
by palanolho
Greetings everyone,
I'm trying to create an archive and place some files on it.
I have created a button to ask for the archive name (to create a new archive) and them I add some file with data to the archive.
My script is not working and no file is created.
Anyone can explain me what am I doing wrong?
Code: Select all
on mouseUp
ask file "Please name your file:"
put (it & ".b2p") into projectPath
answer projectPath
revZipOpenArchive projectPath, "write"
revZipAddUncompressedItemWithData projectPath, "config.xml", "<?xml version='1.0'?>" \
&& "<settings></settings>"
revZipCloseArchive projectPath
end mouseUp
Many thanks
- Miguel Pinto
Re: revZip - Create new Archive questions
Posted: Sun Aug 04, 2013 9:37 pm
by Simon
Hi Miguel,
I "think" I'm going to apologize for LC.
Try this:
Code: Select all
on mouseUp
ask file "Please name your file:"
put (it & ".b2p") into projectPath
answer projectPath
revZipOpenArchive projectPath, "write"
put "<?xml version='1.0'?>" && "<settings></settings>" into tFileContent
revZipAddUncompressedItemWithData projectPath, "config.xml", "tFileContent"
revZipCloseArchive projectPath
end mouseUp
When does one ever put a variable in quotes???
UGH!
Well that should work for you anyways.
Simon
Re: revZip - Create new Archive questions
Posted: Mon Aug 05, 2013 6:35 am
by dave_probertGA6e24
Wow!!!
If that is the way it works then we really should get the dev teams to fix it - 'cos that definitely is not a good syntax or even obvious from the Dictionary.
Looking at the Dictionary entry example shows that Miguel's code should have worked.
But looking at the description says that it's just a Variable. I guess whoever wrote that was having an off day.
Good catch Simon.
Cheers,
Dave
Re: revZip - Create new Archive questions
Posted: Mon Aug 05, 2013 7:50 am
by Simon
I really don't want to read this post again...
I think I'll have a beer.
From the film
Apocalypse Now (1979)
"The horror... The horror"
Simon
Re: revZip - Create new Archive questions
Posted: Mon Aug 05, 2013 9:23 am
by dave.kilroy
Yes putting variables in quotes IS weird
Simon wrote:When does one ever put a variable in quotes???
UGH!
But not unheard of:
Code: Select all
revExecuteSQL tDatabaseID,tSQL,"tArray"
Re: revZip - Create new Archive questions
Posted: Mon Aug 05, 2013 6:22 pm
by jacque
Variables in quotes only happen when dealing with externals. Due to their implementation, and for reasons I don't quite understand, the quotes are necessary in order to send the variable content to the external code. This is all likely to change when the new syntax parser is finished.
Re: revZip - Create new Archive questions
Posted: Thu Aug 08, 2013 8:37 pm
by palanolho
I just need one more hint on this matter ...
I have this script
Code: Select all
on mouseUp
ask "Name your Project"
put it into vProjectName
ask file "Please name your file:" with filter "my zip file, *.zip"
if it = empty then
exit to top
end if
if not (it ends with ".zip") then put ".zip" after it
put it into vProjectPath
startProject vProjectName, vProjectPath
end mouseUp
on startProject tName, tPath
revZipOpenArchive tPath, "write"
put "<?xml version='1.0'?>" & return \
& "<project>" & return \
& tab & "<settings>" & return \
& tab & tab & "<projectname>" & tName & "</projectname>" & return \
& tab & "</settings>" & return \
& "</project>" & return \
into tFileContent
revZipAddUncompressedItemWithData tPath, "config.xml", "tFileContent"
revZipCloseArchive tPath
end startProject
when I execute the code, I choose a name, I choose new name for the file and the scrip creates a new ZIP file with the XML inside and everything is OK
If I execute the script again but this time I give a new name for the project but select the previous created zip, the system ask me if I want to replace the existing file, but at the end, the original file is intact the nothing was changed.
Why is this happening? how can I reply an existing file when creating an archive with a name that already exist?
many thanks
Re: revZip - Create new Archive questions
Posted: Thu Aug 08, 2013 9:47 pm
by Simon
Hi Miguel,
Not sure why the OS isn't deleting the file but here is a workaround:
Code: Select all
...
if not (it ends with ".zip") then put ".zip" after it
put it into vProjectPath
if there is a file vProjectPath then delete file vProjectPath --delete the file specifically
...
Canceling out of the "Save As" exits to top.
Simon
Re: revZip - Create new Archive questions
Posted: Thu Aug 08, 2013 9:54 pm
by palanolho
thanks

it works.
but its weird that its not automatically replacing the file. It should, I presume...
many thanks
- Miguel
Re: revZip - Create new Archive questions
Posted: Fri Aug 09, 2013 6:10 pm
by jacque
The ask and answer file commands link to the OS and return a file path. The OS itself is what interrupts and asks if you want to replace an existing file. If you say yes, it returns that file path. If you say no, it returns you to the dialog so that you can choose another path. In either case, the file itself is not accessed in any way. The dialog just gives your script a path to use.
In your script, whether or not the OS asks if you want to replace a file, you don't use that file path anyway. You use a new path created with the name parameter. So the orignal file isn't changed or overwritten because you aren't altering it.
There is no need to delete the original unless you want to. The other way to manage it would be to use the original path and alter that file instead of creating a new one.