473,762 Members | 8,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some help...

This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could point
me in the right direction.

The history:
My work involves creating custom packages of our software product for golf
courses that purchase our software. The course data is kept as a back up in
the event the course needs us to replace their custom files. Each course has
a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our customer
base increases.

The solution:
Compress each course folder into an individual .cab file containing all of
the course's custom files and then archive these files to storage media such
as CD/DVD.

Where I need help:
I found some code for implementing a command line window and passing it a
string through a stream. The command window is being instantiated, but the
string is not getting passed or my syntax for running the makecab utility is
off-base. I've spent several hours looking for sample code that would
explain the makecab syntax and I've also tried to determine if the
parameters are being passed in to the Sub correctly. I've set a break at the
line where the string should be passed to the command window, but I can not
seem to get a respnse from the watches that have been set. I've included a
copy of the sub that I'm using to compress the files. If this is not the
correct forum for this, I do apologize. A nudge in the correct direction
would be deeply appreciated.

Private Sub CompressFolder( ByVal ToFolder As String, ByVal FromFolder As
String, ByVal FinalFile As String)

Dim CompressProcess As Process = New Process

CompressProcess .StartInfo.File Name = "cmd.exe"

CompressProcess .StartInfo.UseS hellExecute = False

CompressProcess .StartInfo.Crea teNoWindow = True

CompressProcess .StartInfo.Redi rectStandardInp ut = True

CompressProcess .StartInfo.Redi rectStandardOut put = True

CompressProcess .StartInfo.Redi rectStandardErr or = True

CompressProcess .Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess .StandardInput

stmStreamIn.Aut oFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess .StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess .StandardError

stmStreamIn.Wri te("makecab.ex e /L %ToFolder% %FromFolder% %FinalFile%" &
System.Environm ent.NewLine)

stmStreamIn.Wri te("exit" & System.Environm ent.NewLine)

If Not CompressProcess .HasExited Then

CompressProcess .Kill()

End If

stmStreamIn.Clo se()

stmStreamOut.Cl ose()

stmStreamErr.Cl ose()

End Sub
Dec 9 '06 #1
46 2533
Nice idea, but you're slightly on the wrong track with your usage of
makecab.exe.

The /L switch can only be used to compress a single source file into a
single .cab file, so unless you want gazillions of .cab files that's not
much good.

The /F switch is used to compress multiple source files into a into a single
..cab file, but it's a bit more complicated that you think.

Makecab.exe does not use standardinput/output. With the /F switch it reads
the required information from a definition file and it, in addition to
creating the .cab file, writes summary information to a 'report' file and
other information to a 'inf' file. Don't even consider the whys and
wherefores of this because what you are attempting to do is slight
non-standard compared to what makecab.exe was actually designed for.

Now for the nitty gritty.

The first thing you need to do is write a definition file, lets call it
test.ddf for the purpose of the exercise:

Dim _sw As New StreamWriter("t est.ddf")
_sw.WriteLine(" .Set SourceDir=" & FromFolder)
_sw.WriteLine(" .Set CabinetNameTemp late=" & FinalFile)
_sw.WriteLine(" .Set DiskDirectoryTe mplate=" & ToFolder)
_sw.WriteLine(" .Set InfFileName=tes t.inf")
_sw.WriteLine(" .Set RptFileName=tes t.rpt")
_sw.WriteLine(" .Set Cabinet=ON")
_sw.WriteLine(" .Set Compress=ON")
Dim _files as String() = Directory.GetFi les(FromFolder)
For Each _file as String In _files
_sw.WriteLine(F ile.GetFileName (_file))
Next
_sw.Close()

Makecab.exe is very unforgiving if you get the syntax of the definition file
wrong.

If FromFolder does not exist then it will fail.

It will create the folder indicated by the final node of ToFolder, but it
will fail if any of the folders higher up the hierachy do not exist. This
can be circumvented by executing:

If Not Directory.Exist s(Path.GetDirec tory(ToFolder)) Then
Directory.Creat eDirectory(Path .GetDirectory(T oFolder))

Note that ALL the files that you want in the .cab file MUST be included in
the definition file. As you can see this is easily achieved by iterating
through all the files in FromFolder. Also note that baecause .Set SourceDir
is specified, only the actual filename is required and not the full path.

The next thing is to execute makecab.exe:

Process.Start(" makecab.exe", "/F test.ddf").Wait ForExit()

A command window will momentarily appear and disappear.

Now you will probably want to see what happened. Plonk a TextBox on the
form, make it multiline, set it's Font to your favourite mono-spaced font
and size it to a decent size.

TextBox1.Text = File.ReadAllTex t("test.rpt")

Now all you have to do is tidy up after yourself:

File.Delete("te st.ddf")
File.Delete("te st.inf")
File.Delete("te st.rpt")

Supress the File.Delete's if you want to have a look in the test.inf file
but I doubt whether the content of it will be of any value to you given what
you are trying to achieve.

The following link will alow you to download the a file called Cabsdk.exe
hich contains, among other things, a Word document that provides a lot of
detail about makecab.exe.

http://download.microsoft.com/downlo...-us/Cabsdk.exe

Have fun!
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:bZ******** *************** *******@comcast .com...
This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could
point me in the right direction.

The history:
My work involves creating custom packages of our software product for golf
courses that purchase our software. The course data is kept as a back up
in the event the course needs us to replace their custom files. Each
course has a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our
customer base increases.

The solution:
Compress each course folder into an individual .cab file containing all of
the course's custom files and then archive these files to storage media
such as CD/DVD.

Where I need help:
I found some code for implementing a command line window and passing it a
string through a stream. The command window is being instantiated, but the
string is not getting passed or my syntax for running the makecab utility
is off-base. I've spent several hours looking for sample code that would
explain the makecab syntax and I've also tried to determine if the
parameters are being passed in to the Sub correctly. I've set a break at
the line where the string should be passed to the command window, but I
can not seem to get a respnse from the watches that have been set. I've
included a copy of the sub that I'm using to compress the files. If this
is not the correct forum for this, I do apologize. A nudge in the correct
direction would be deeply appreciated.

Private Sub CompressFolder( ByVal ToFolder As String, ByVal FromFolder As
String, ByVal FinalFile As String)

Dim CompressProcess As Process = New Process

CompressProcess .StartInfo.File Name = "cmd.exe"

CompressProcess .StartInfo.UseS hellExecute = False

CompressProcess .StartInfo.Crea teNoWindow = True

CompressProcess .StartInfo.Redi rectStandardInp ut = True

CompressProcess .StartInfo.Redi rectStandardOut put = True

CompressProcess .StartInfo.Redi rectStandardErr or = True

CompressProcess .Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess .StandardInput

stmStreamIn.Aut oFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess .StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess .StandardError

stmStreamIn.Wri te("makecab.ex e /L %ToFolder% %FromFolder% %FinalFile%" &
System.Environm ent.NewLine)

stmStreamIn.Wri te("exit" & System.Environm ent.NewLine)

If Not CompressProcess .HasExited Then

CompressProcess .Kill()

End If

stmStreamIn.Clo se()

stmStreamOut.Cl ose()

stmStreamErr.Cl ose()

End Sub


Dec 9 '06 #2
Stephany,

Thank you so very much. I will give this a go when I get home from work. The
link to the CabSDK I've already downloaded, but I didn't see the .doc, so
I'll go through my download again. Cheers!

"Stephany Young" <noone@localhos twrote in message
news:u5******** ******@TK2MSFTN GP03.phx.gbl...
Nice idea, but you're slightly on the wrong track with your usage of
makecab.exe.

Dec 9 '06 #3
On Sat, 9 Dec 2006 00:34:16 -0700, Bruce W. Darby wrote:
This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could point
me in the right direction.

The history:
My work involves creating custom packages of our software product for golf
courses that purchase our software. The course data is kept as a back up in
the event the course needs us to replace their custom files. Each course has
a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our customer
base increases.

The solution:
Compress each course folder into an individual .cab file containing all of
the course's custom files and then archive these files to storage media such
as CD/DVD.
If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com
Dec 9 '06 #4
Rad,

I have downloaded the SharpZip files and am reading into them, but at this
point in time, I doubt my ability as a programmer to be able to incorporate
this on a module level. I do understand that there are better compression
methods available, but I'd like to start small and work my way up the
ladder, so to speak. Thank you very much for your assistance.

Bruce

"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:rn******** *******@thinker sroom.com...
On Sat, 9 Dec 2006 00:34:16 -0700, Bruce W. Darby wrote:
>This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could
point
me in the right direction.

The history:
My work involves creating custom packages of our software product for
golf
courses that purchase our software. The course data is kept as a back up
in
the event the course needs us to replace their custom files. Each course
has
a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our
customer
base increases.

The solution:
Compress each course folder into an individual .cab file containing all
of
the course's custom files and then archive these files to storage media
such
as CD/DVD.

If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to
accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com

Dec 10 '06 #5
It sounds like losser mentality to me, insecurities in your ability to
learn. Maybe programming just isn't the right thing for you. Don't feel
too ashamed, not everyone can reach the highest levels. You can always
try something else less demanding.

The Grand Master
Bruce W. Darby wrote:
Rad,

I have downloaded the SharpZip files and am reading into them, but at this
point in time, I doubt my ability as a programmer to be able to incorporate
this on a module level. I do understand that there are better compression
methods available, but I'd like to start small and work my way up the
ladder, so to speak. Thank you very much for your assistance.

Bruce

"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:rn******** *******@thinker sroom.com...
On Sat, 9 Dec 2006 00:34:16 -0700, Bruce W. Darby wrote:
This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could
point
me in the right direction.

The history:
My work involves creating custom packages of our software product for
golf
courses that purchase our software. The course data is kept as a back up
in
the event the course needs us to replace their custom files. Each course
has
a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our
customer
base increases.

The solution:
Compress each course folder into an individual .cab file containing all
of
the course's custom files and then archive these files to storage media
such
as CD/DVD.
If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to
accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com
Dec 11 '06 #6

"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:rn******** *******@thinker sroom.com...
If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to
accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com
Took a look into the sharpziplib you suggested and found it easier than
usual to add it to my solution, but I am having a bit of an issue. Not sure
what I'm doing wrong and hope that you can enlightem my fuzzy brain. When I
start the compression, I get an UnauthorizedAcc essException thrown as the
program trys to recurse through the subfolders in FromFolder. I can
understand that it's treating the subdirectories as files, but cannot figure
out why. Any tweaks or nudges? Code follows...

Private Sub CompressFolder( )

Dim strSourceDir As String = txtSelectDir.Te xt

If strSourceDir.Le ngth = 0 Then

MsgBox("Please specify a directory")

txtSelectDir.Fo cus()

Exit Sub

Else

If Not Directory.Exist s(strSourceDir) Then

MsgBox("Directo ry not found")

txtSelectDir.Fo cus()

Exit Sub

End If

End If

Dim strTargetDir As String = txtWriteDir.Tex t

If strTargetDir.Le ngth = 0 Then

MsgBox("Please specify a directory")

txtWriteDir.Foc us()

Exit Sub

Else

If Not Directory.Exist s(strTargetDir) Then

MsgBox("Directo ry not found")

txtWriteDir.Foc us()

Exit Sub

End If

End If

Dim arystrmFolderNa mes() As String = Directory.GetDi rectories(strSo urceDir)

Dim strmZipOutputSt ream As ZipOutputStream

Dim intCounter As Integer

Dim strTargetFile As String = strTargetDir &
arystrmFolderNa mes(intCounter) .LastIndexOfAny ("\")

strmZipOutputSt ream = New ZipOutputStream (File.Create(st rTargetFile))

strmZipOutputSt ream.SetLevel(9 )

Dim strFolder As String

For Each strFolder In arystrmFolderNa mes

Dim strmFile As FileStream = File.OpenRead(s trFolder)

Dim abyBuffer(strmF ile.Length - 1) As Byte

strmFile.Read(a byBuffer, 0, abyBuffer.Lengt h)

Dim objZipEntry As ZipEntry = New ZipEntry(strFol der)

objZipEntry.Dat eTime = DateTime.Now

objZipEntry.Siz e = strmFile.Length

strmFile.Close( )

strmZipOutputSt ream.PutNextEnt ry(objZipEntry)

strmZipOutputSt ream.Write(abyB uffer, 0, abyBuffer.Lengt h)

intCounter += 1

Next

strmZipOutputSt ream.Finish()

strmZipOutputSt ream.Close()

MsgBox("Operati on completed")

End Sub

P.S. Please forgive my sloppy coding
Dec 11 '06 #7
Stephany,

I've gotten a whole lot more understanding of makecab because of your
assistance. I attempted to modify the code to recurse subfolders, but
couldn't get the modified code to work. Started digging around on the
Internet and in an obscure corner found this site.
http://www.codeproject.com/cs/files/...essExtract.asp

Have you ever heard of or used this tool?

Bruce

"Stephany Young" <noone@localhos twrote in message
news:u5******** ******@TK2MSFTN GP03.phx.gbl...
Nice idea, but you're slightly on the wrong track with your usage of
makecab.exe.

The /L switch can only be used to compress a single source file into a
single .cab file, so unless you want gazillions of .cab files that's not
much good.

The /F switch is used to compress multiple source files into a into a
single .cab file, but it's a bit more complicated that you think.

Makecab.exe does not use standardinput/output. With the /F switch it reads
the required information from a definition file and it, in addition to
creating the .cab file, writes summary information to a 'report' file and
other information to a 'inf' file. Don't even consider the whys and
wherefores of this because what you are attempting to do is slight
non-standard compared to what makecab.exe was actually designed for.

Now for the nitty gritty.

The first thing you need to do is write a definition file, lets call it
test.ddf for the purpose of the exercise:

Dim _sw As New StreamWriter("t est.ddf")
_sw.WriteLine(" .Set SourceDir=" & FromFolder)
_sw.WriteLine(" .Set CabinetNameTemp late=" & FinalFile)
_sw.WriteLine(" .Set DiskDirectoryTe mplate=" & ToFolder)
_sw.WriteLine(" .Set InfFileName=tes t.inf")
_sw.WriteLine(" .Set RptFileName=tes t.rpt")
_sw.WriteLine(" .Set Cabinet=ON")
_sw.WriteLine(" .Set Compress=ON")
Dim _files as String() = Directory.GetFi les(FromFolder)
For Each _file as String In _files
_sw.WriteLine(F ile.GetFileName (_file))
Next
_sw.Close()

Makecab.exe is very unforgiving if you get the syntax of the definition
file wrong.

If FromFolder does not exist then it will fail.

It will create the folder indicated by the final node of ToFolder, but it
will fail if any of the folders higher up the hierachy do not exist. This
can be circumvented by executing:

If Not Directory.Exist s(Path.GetDirec tory(ToFolder)) Then
Directory.Creat eDirectory(Path .GetDirectory(T oFolder))

Note that ALL the files that you want in the .cab file MUST be included in
the definition file. As you can see this is easily achieved by iterating
through all the files in FromFolder. Also note that baecause .Set
SourceDir is specified, only the actual filename is required and not the
full path.

The next thing is to execute makecab.exe:

Process.Start(" makecab.exe", "/F test.ddf").Wait ForExit()

A command window will momentarily appear and disappear.

Now you will probably want to see what happened. Plonk a TextBox on the
form, make it multiline, set it's Font to your favourite mono-spaced font
and size it to a decent size.

TextBox1.Text = File.ReadAllTex t("test.rpt")

Now all you have to do is tidy up after yourself:

File.Delete("te st.ddf")
File.Delete("te st.inf")
File.Delete("te st.rpt")

Supress the File.Delete's if you want to have a look in the test.inf file
but I doubt whether the content of it will be of any value to you given
what you are trying to achieve.

The following link will alow you to download the a file called Cabsdk.exe
hich contains, among other things, a Word document that provides a lot of
detail about makecab.exe.
http://download.microsoft.com/downlo...-us/Cabsdk.exe

Have fun!
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:bZ******** *************** *******@comcast .com...
>This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could
point me in the right direction.

The history:
My work involves creating custom packages of our software product for
golf courses that purchase our software. The course data is kept as a
back up in the event the course needs us to replace their custom files.
Each course has a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our
customer base increases.

The solution:
Compress each course folder into an individual .cab file containing all
of the course's custom files and then archive these files to storage
media such as CD/DVD.

Where I need help:
I found some code for implementing a command line window and passing it a
string through a stream. The command window is being instantiated, but
the string is not getting passed or my syntax for running the makecab
utility is off-base. I've spent several hours looking for sample code
that would explain the makecab syntax and I've also tried to determine if
the parameters are being passed in to the Sub correctly. I've set a break
at the line where the string should be passed to the command window, but
I can not seem to get a respnse from the watches that have been set. I've
included a copy of the sub that I'm using to compress the files. If this
is not the correct forum for this, I do apologize. A nudge in the correct
direction would be deeply appreciated.

Private Sub CompressFolder( ByVal ToFolder As String, ByVal FromFolder As
String, ByVal FinalFile As String)

Dim CompressProcess As Process = New Process

CompressProces s.StartInfo.Fil eName = "cmd.exe"

CompressProces s.StartInfo.Use ShellExecute = False

CompressProces s.StartInfo.Cre ateNoWindow = True

CompressProces s.StartInfo.Red irectStandardIn put = True

CompressProces s.StartInfo.Red irectStandardOu tput = True

CompressProces s.StartInfo.Red irectStandardEr ror = True

CompressProces s.Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess .StandardInput

stmStreamIn.Au toFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess .StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess .StandardError

stmStreamIn.Wr ite("makecab.ex e /L %ToFolder% %FromFolder% %FinalFile%" &
System.Environ ment.NewLine)

stmStreamIn.Wr ite("exit" & System.Environm ent.NewLine)

If Not CompressProcess .HasExited Then

CompressProces s.Kill()

End If

stmStreamIn.Cl ose()

stmStreamOut.C lose()

stmStreamErr.C lose()

End Sub



Dec 11 '06 #8
You sure are having a bit of an issue!!!!!! :)

Before you even attempt to go any further, I stringly recommend that you
'turn' Option Strict and Option Explicit 'on' for ALL your VB.NET projects
and solutions. You can do this in Tools/Options. Expand the Projects and
Solutions node and select VB Defaults. Settings those to 'on' in there will
ensure that Option Strict and Option Explicit are automatically 'on' for all
new projects. For existing projects you will need to change the settings for
each individual project.

Option Explicit 'on' means that you must explicitly define each variable
before you can use it.

Option Strict 'on' means that the complier will make NO assumptions about
what the code should do. When you turn it on for this project than a number
of compile-time 'errors' will appear and you will need to correct them all.

A number of the problems in the code fragment are caused by Option Strict
being 'off'. If you leave it turned off then you will continue to tear your
hair out because you not be able to spot various subtle problems.

Now for the nitty gritty.

Dim arystrmFolderNa mes() As String =
Directory.GetDi rectories(strSo urceDir)

This line create a string array that contains 1 element for each sub-folder
in whatever folder strSourceDir is pointing to. Each element contains the
name of (or the path to) a single sub-folder.

With the line (inside the loop):

Dim strmFile As FileStream = File.OpenRead(s trFolder)

you are attempting to open a sub-folder for reading and that is where you
are falling over. A folder (or directory) cannot be opened as if it were a
file. You need to walk the 'tree' and deal with each and every file in each
and every sub-folder.

Before we deal with that, the line:

Dim strTargetFile As String = strTargetDir &
arystrmFolderNa mes(intCounter) .LastIndexOfAny ("\")

must also be causing you problems. If your strTargetDir is "C:\Temp\" and
arystrmFolderNa mes(intCounter) is "C:\Data\Su bA" then strTargetFile will
become "C:\Temp\7" and I don't really think that is what you intend. I
suspect that you are looking for strTargetFile to be "C:\Temp\SubA.z ip". If
that is what you are looking for than you need to use something like:

Dim strTargetFile As String =
Path.ChangeExte nsion(Path.Comb ine(strTargetDi r,
Path.GetFileNam e(arystrmFolder Names(intCounte r))), "zip")

You use the phrase 'as the program trys to recurse through the subfolders in
FromFolder', but what your code is, in fact, doing is iterating through the
subfolders in FromFolder.

You do actually need to recursively walk the tree that starts at FromFolder,
dealing with every sub-folder including nested sub-folders and handling
every file that you encounter. This can be done with something like:

Private Sub RecurseFolders( ByVal folder as String)

Dim _files as String() = Directory.GetFi les(folder)

For Each _file As String In _files
Dim strmFile As FileStream = File.OpenRead(_ file)
Dim abyBuffer(strmF ile.Length - 1) As Byte
strmFile.Read(a byBuffer, 0, abyBuffer.Lengt h)
strmFile.Close( )
Dim objZipEntry As New ZipEntry(_file)
objZipEntry.Dat eTime = DateTime.Now
objZipEntry.Siz e = abyBuffer.Lengt h
strmZipOutputSt ream.PutNextEnt ry(objZipEntry)
strmZipOutputSt ream.Write(abyB uffer, 0, abyBuffer.Lengt h)
Next

Dim _folders As String() = Directory.GetDi rectories(folde r)

For Each _folder in _folders
RecurseFolders( FromFolder)
Next

End Sub

Call this method for the appropriate place with:

RecurseFolders( FromFolder)

Let us know how you get on.
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:FK******** *************** *******@comcast .com...
>
"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:rn******** *******@thinker sroom.com...
>If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to
accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com

Took a look into the sharpziplib you suggested and found it easier than
usual to add it to my solution, but I am having a bit of an issue. Not
sure what I'm doing wrong and hope that you can enlightem my fuzzy brain.
When I start the compression, I get an UnauthorizedAcc essException thrown
as the program trys to recurse through the subfolders in FromFolder. I can
understand that it's treating the subdirectories as files, but cannot
figure out why. Any tweaks or nudges? Code follows...

Private Sub CompressFolder( )

Dim strSourceDir As String = txtSelectDir.Te xt

If strSourceDir.Le ngth = 0 Then

MsgBox("Please specify a directory")

txtSelectDir.Fo cus()

Exit Sub

Else

If Not Directory.Exist s(strSourceDir) Then

MsgBox("Directo ry not found")

txtSelectDir.Fo cus()

Exit Sub

End If

End If

Dim strTargetDir As String = txtWriteDir.Tex t

If strTargetDir.Le ngth = 0 Then

MsgBox("Please specify a directory")

txtWriteDir.Foc us()

Exit Sub

Else

If Not Directory.Exist s(strTargetDir) Then

MsgBox("Directo ry not found")

txtWriteDir.Foc us()

Exit Sub

End If

End If

Dim arystrmFolderNa mes() As String =
Directory.GetDi rectories(strSo urceDir)

Dim strmZipOutputSt ream As ZipOutputStream

Dim intCounter As Integer

Dim strTargetFile As String = strTargetDir &
arystrmFolderNa mes(intCounter) .LastIndexOfAny ("\")

strmZipOutputSt ream = New ZipOutputStream (File.Create(st rTargetFile))

strmZipOutputSt ream.SetLevel(9 )

Dim strFolder As String

For Each strFolder In arystrmFolderNa mes

Dim strmFile As FileStream = File.OpenRead(s trFolder)

Dim abyBuffer(strmF ile.Length - 1) As Byte

strmFile.Read(a byBuffer, 0, abyBuffer.Lengt h)

Dim objZipEntry As ZipEntry = New ZipEntry(strFol der)

objZipEntry.Dat eTime = DateTime.Now

objZipEntry.Siz e = strmFile.Length

strmFile.Close( )

strmZipOutputSt ream.PutNextEnt ry(objZipEntry)

strmZipOutputSt ream.Write(abyB uffer, 0, abyBuffer.Lengt h)

intCounter += 1

Next

strmZipOutputSt ream.Finish()

strmZipOutputSt ream.Close()

MsgBox("Operati on completed")

End Sub

P.S. Please forgive my sloppy coding


Dec 11 '06 #9
I haven't come across that one before but it is certainly one of the better
presented articles and projects at CodeProject.

I had a dig in the source code and it looks OK. The CompressFolder will
compress everything in a given tree and this means that you wouldn't have to
worry abot doing any recursion yourself. I note that it also has the ability
to encrypt the compressed data.

I can only suggest that you try it and see if it will work for you. If you
do then also test the extraction methods to ensure that you can actually
'restore' the data from the compressed file.

Out of interest, what sort of data quantity are you talking about in a given
tree. Are you talking about multi-Gigabytes, because if you are then you
could hit some 'ceiling' or other.

Let us know how you get on.
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:C4******** *************** *******@comcast .com...
Stephany,

I've gotten a whole lot more understanding of makecab because of your
assistance. I attempted to modify the code to recurse subfolders, but
couldn't get the modified code to work. Started digging around on the
Internet and in an obscure corner found this site.
http://www.codeproject.com/cs/files/...essExtract.asp

Have you ever heard of or used this tool?

Bruce

"Stephany Young" <noone@localhos twrote in message
news:u5******** ******@TK2MSFTN GP03.phx.gbl...
>Nice idea, but you're slightly on the wrong track with your usage of
makecab.exe.

The /L switch can only be used to compress a single source file into a
single .cab file, so unless you want gazillions of .cab files that's not
much good.

The /F switch is used to compress multiple source files into a into a
single .cab file, but it's a bit more complicated that you think.

Makecab.exe does not use standardinput/output. With the /F switch it
reads the required information from a definition file and it, in addition
to creating the .cab file, writes summary information to a 'report' file
and other information to a 'inf' file. Don't even consider the whys and
wherefores of this because what you are attempting to do is slight
non-standard compared to what makecab.exe was actually designed for.

Now for the nitty gritty.

The first thing you need to do is write a definition file, lets call it
test.ddf for the purpose of the exercise:

Dim _sw As New StreamWriter("t est.ddf")
_sw.WriteLine(" .Set SourceDir=" & FromFolder)
_sw.WriteLine(" .Set CabinetNameTemp late=" & FinalFile)
_sw.WriteLine(" .Set DiskDirectoryTe mplate=" & ToFolder)
_sw.WriteLine(" .Set InfFileName=tes t.inf")
_sw.WriteLine(" .Set RptFileName=tes t.rpt")
_sw.WriteLine(" .Set Cabinet=ON")
_sw.WriteLine(" .Set Compress=ON")
Dim _files as String() = Directory.GetFi les(FromFolder)
For Each _file as String In _files
_sw.WriteLine(F ile.GetFileName (_file))
Next
_sw.Close()

Makecab.exe is very unforgiving if you get the syntax of the definition
file wrong.

If FromFolder does not exist then it will fail.

It will create the folder indicated by the final node of ToFolder, but it
will fail if any of the folders higher up the hierachy do not exist. This
can be circumvented by executing:

If Not Directory.Exist s(Path.GetDirec tory(ToFolder)) Then
Directory.Crea teDirectory(Pat h.GetDirectory( ToFolder))

Note that ALL the files that you want in the .cab file MUST be included
in the definition file. As you can see this is easily achieved by
iterating through all the files in FromFolder. Also note that baecause
.Set SourceDir is specified, only the actual filename is required and not
the full path.

The next thing is to execute makecab.exe:

Process.Start(" makecab.exe", "/F test.ddf").Wait ForExit()

A command window will momentarily appear and disappear.

Now you will probably want to see what happened. Plonk a TextBox on the
form, make it multiline, set it's Font to your favourite mono-spaced font
and size it to a decent size.

TextBox1.Text = File.ReadAllTex t("test.rpt")

Now all you have to do is tidy up after yourself:

File.Delete("te st.ddf")
File.Delete("te st.inf")
File.Delete("te st.rpt")

Supress the File.Delete's if you want to have a look in the test.inf file
but I doubt whether the content of it will be of any value to you given
what you are trying to achieve.

The following link will alow you to download the a file called Cabsdk.exe
hich contains, among other things, a Word document that provides a lot of
detail about makecab.exe.
http://download.microsoft.com/downlo...-us/Cabsdk.exe

Have fun!
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:bZ******* *************** ********@comcas t.com...
>>This will be my very first VB.Net application and it's pretty simple.
But I've got a snag in my syntax somewhere. Was hoping that someone
could point me in the right direction.

The history:
My work involves creating custom packages of our software product for
golf courses that purchase our software. The course data is kept as a
back up in the event the course needs us to replace their custom files.
Each course has a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our
customer base increases.

The solution:
Compress each course folder into an individual .cab file containing all
of the course's custom files and then archive these files to storage
media such as CD/DVD.

Where I need help:
I found some code for implementing a command line window and passing it
a string through a stream. The command window is being instantiated, but
the string is not getting passed or my syntax for running the makecab
utility is off-base. I've spent several hours looking for sample code
that would explain the makecab syntax and I've also tried to determine
if the parameters are being passed in to the Sub correctly. I've set a
break at the line where the string should be passed to the command
window, but I can not seem to get a respnse from the watches that have
been set. I've included a copy of the sub that I'm using to compress the
files. If this is not the correct forum for this, I do apologize. A
nudge in the correct direction would be deeply appreciated.

Private Sub CompressFolder( ByVal ToFolder As String, ByVal FromFolder As
String, ByVal FinalFile As String)

Dim CompressProcess As Process = New Process

CompressProce ss.StartInfo.Fi leName = "cmd.exe"

CompressProce ss.StartInfo.Us eShellExecute = False

CompressProce ss.StartInfo.Cr eateNoWindow = True

CompressProce ss.StartInfo.Re directStandardI nput = True

CompressProce ss.StartInfo.Re directStandardO utput = True

CompressProce ss.StartInfo.Re directStandardE rror = True

CompressProce ss.Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess .StandardInput

stmStreamIn.A utoFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess .StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess .StandardError

stmStreamIn.W rite("makecab.e xe /L %ToFolder% %FromFolder% %FinalFile%" &
System.Enviro nment.NewLine)

stmStreamIn.W rite("exit" & System.Environm ent.NewLine)

If Not CompressProcess .HasExited Then

CompressProce ss.Kill()

End If

stmStreamIn.C lose()

stmStreamOut. Close()

stmStreamErr. Close()

End Sub




Dec 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6328
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
5
2194
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows: Objectives The purpose of this assignment is to have you practice the design of object-oriented classes, including one or more of the following concepts
0
1839
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities, all dont work "Re:" need help "Re:need help"
9
2937
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
7
3306
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
15
4641
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
16
2538
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
8
2750
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
0
3961
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
20
4283
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9378
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.