PDA

View Full Version : Writing dwg's to a zip file.



kdayman
2008-07-24, 06:20 PM
I'm gathering information before I start writing a routine that will be like pack'n'go. Basically I will be archiving a number of drawing files, possible a few image files, and a ctb file. I can easily write each package to it's own directory, however writing them to a zip file would be far more elegant. Does anyone have any information on writing files to a zip file that would get me started?

Thanks in advance,

Kelly

Opie
2008-07-24, 06:30 PM
This Tek-Tips Forum thread (http://www.tek-tips.com/viewthread.cfm?qid=1231429&page=1) discusses how to add files to a compressed files.

kdayman
2008-07-24, 06:39 PM
That's exactly what I was looking for. Thank you very much!

Comach
2008-07-25, 10:25 AM
I'm gathering information before I start writing a routine that will be like pack'n'go. Basically I will be archiving a number of drawing files, possible a few image files, and a ctb file. I can easily write each package to it's own directory, however writing them to a zip file would be far more elegant. Does anyone have any information on writing files to a zip file that would get me started?

Thanks in advance,

Kelly

Is there any reason why you would not wish to use 'eTransmit'?

You can select any number of drawings/files to the package and save this to a zip file.

kdayman
2008-07-29, 05:34 PM
Is there any reason why you would not wish to use 'eTransmit'?

You can select any number of drawings/files to the package and save this to a zip file.

We have some clients that have very specific requests (these are saved in an SQL DB) and as part of our Quality Management ISO Certification we write what file files were sent when and by who to the DB. eTransmit just doesn't cut it.

I have been able to write the contents of a directory to a zip file. Here is the basic method I'm using:


Public Sub testzip0()
MakeZip ("C:\test.zip")
AddDirToZip ("C:\test.zip"), ("C:\temp")
End Sub

Function MakeZip(Path)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ts = FSO.OpenTextFile(Path, 8, vbTrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For X = 0 To 17
BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip
Set objFolder = Nothing
Set objShell = Nothing
Set FSO = Nothing
Set ts = Nothing
End Function

Function AddDirToZip(ZipFile, Dir)
Set objApp = CreateObject("Shell.Application")
objApp.NameSpace(ZipFile).CopyHere objApp.NameSpace(Dir).Items
End Function

However I would like to write individual files to the zip file, it not turning out to be as easy as I thought.

Any ideas???


Moderator Note:

Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

Comach
2008-07-30, 12:37 AM
We have some clients that have very specific requests (these are saved in an SQL DB) and as part of our Quality Management ISO Certification we write what file files were sent when and by who to the DB. eTransmit just doesn't cut it.

I am not sure that I can help you further with this. I am bit surprised that you could not work with the etransmit as this does give you the option to add individual files and also to add additional Notes to the transmittal which could be used to record details of the sender.

Anyway I wish you success with your endeavours.

Ed Jobe
2008-07-30, 02:21 PM
Do you have any 3D party zip software installed other than windows compressed folders? They sometimes have command line versions that you can script.

kdayman
2008-07-30, 05:12 PM
Got it working, here is the code...



Public Function AddFileToZip(ZipName, FileToZip)
Dim FSO As Object
Dim oApp As Object
If Dir(ZipName) = "" Then
Open ZipName For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
End If
Set oApp = CreateObject("Shell.Application")
oApp.NameSpace(ZipName).CopyHere (FileToZip)
'Keep script waiting until Compressing is done
On Error Resume Next
Do Until oApp.NameSpace(ZipName).Items.Count = 1
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True
Set oApp = Nothing
Set FSO = Nothing
End Function


Thank you very much to everyone who replied to this post.

I have however hit my next bump in the road, but I'll start a new post.

Kelly

kdayman
2008-08-07, 10:24 PM
I've run into a problem, it works great for local files (on C:\ drive) however when I try with either the file to be zipped or the zip file being on a network drive I get:



Run-time error '91':

Object variable or With block variable not set


on the following line:


oApp.NameSpace(ZipName).CopyHere (FileToZip)


Any ideas???

kdayman
2008-08-07, 10:51 PM
I just had a thought, my developement machine is not on the network, however I have network drives that point to local folder. For example to see a P:\ drive I use the following dos command



subst P: C:\LocalP


Could this be the problem? (I'm working remotely so I cannot connect to the network to verify this)

kdayman
2008-08-11, 09:52 PM
I'm in the office today and mapped to a real network drive and same problem.

Anyone have any ideas? The only work around I have now is to copy everything into a local temp drive, but that is just messy and unelegant.

kdayman
2008-08-12, 04:16 PM
After much searching I found a tip that it works in 2K but not XP, but in XP if you put an extra set of parentheses around the path it works. I cound not find a reason why but there is speculation that this forces the code to evaluate the string into the data type required. I'm not sure if I buy that, but I know it works.

RobertB
2008-08-12, 05:18 PM
After much searching I found a tip that it works in 2K but not XP, but in XP if you put an extra set of parentheses around the path it works. I cound not find a reason why but there is speculation that this forces the code to evaluate the string into the data type required. I'm not sure if I buy that, but I know it works.Did you mean an extra set parens or quotes?

kdayman
2008-08-12, 05:22 PM
Like this:



oApp.NameSpace((ZipName)).CopyHere ((FileToZip))

RobertB
2008-08-12, 06:13 PM
Thanks for posting the sample. Sounds like a kludge, but as long as it works... ;)