Re: Need some help...



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("test.ddf")
_sw.WriteLine(".Set SourceDir=" & FromFolder)
_sw.WriteLine(".Set CabinetNameTemplate=" & FinalFile)
_sw.WriteLine(".Set DiskDirectoryTemplate=" & ToFolder)
_sw.WriteLine(".Set InfFileName=test.inf")
_sw.WriteLine(".Set RptFileName=test.rpt")
_sw.WriteLine(".Set Cabinet=ON")
_sw.WriteLine(".Set Compress=ON")
Dim _files as String() = Directory.GetFiles(FromFolder)
For Each _file as String In _files
_sw.WriteLine(File.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.Exists(Path.GetDirectory(ToFolder)) Then
Directory.CreateDirectory(Path.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").WaitForExit()

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.ReadAllText("test.rpt")

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

File.Delete("test.ddf")
File.Delete("test.inf")
File.Delete("test.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/download/platformsdk/cab/2.0/w98nt42kmexp/en-us/Cabsdk.exe

Have fun!


"Bruce W. Darby" <kracor@xxxxxxxxxxx> wrote in message
news:bZWdnTYHw_hn--fYnZ2dnUVZ_h2pnZ2d@xxxxxxxxxxxxxx
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.FileName = "cmd.exe"

CompressProcess.StartInfo.UseShellExecute = False

CompressProcess.StartInfo.CreateNoWindow = True

CompressProcess.StartInfo.RedirectStandardInput = True

CompressProcess.StartInfo.RedirectStandardOutput = True

CompressProcess.StartInfo.RedirectStandardError = True

CompressProcess.Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess.StandardInput

stmStreamIn.AutoFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess.StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess.StandardError

stmStreamIn.Write("makecab.exe /L %ToFolder% %FromFolder% %FinalFile%" &
System.Environment.NewLine)

stmStreamIn.Write("exit" & System.Environment.NewLine)

If Not CompressProcess.HasExited Then

CompressProcess.Kill()

End If

stmStreamIn.Close()

stmStreamOut.Close()

stmStreamErr.Close()

End Sub




.



Relevant Pages

  • Re: Need some help...
    ... compress everything in a given tree and this means that you wouldn't have to ... single .cab file, but it's a bit more complicated that you think. ... Dim _files as String() = Directory.GetFiles ... Dim stmStreamIn As IO.StreamWriter = CompressProcess.StandardInput ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need some help...
    ... single .cab file, but it's a bit more complicated that you think. ... Dim _files as String() = Directory.GetFiles ... back up in the event the course needs us to replace their custom files. ... Dim stmStreamIn As IO.StreamWriter = CompressProcess.StandardInput ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Attention Sean - question about CSI
    ... the best compression algorithm you have. ... It should compress very ... which compresses that string to a single bit. ... already there uncompressed, why would you want to uncompress it ...
    (talk.origins)
  • Re: Attention Sean - question about CSI
    ... the best compression algorithm you have. ... It should compress very ... which compresses that string to a single bit. ... from the binary code, and use it to decompress the data, then ...
    (talk.origins)
  • Re: Attention Sean - question about CSI
    ... or the same CSI as a string of the same length where the ... the best compression algorithm you have. ... It should compress very ... which compresses that string to a single bit. ...
    (talk.origins)