Re: Need some help...
- From: "Stephany Young" <noone@localhost>
- Date: Mon, 11 Dec 2006 23:55:48 +1300
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" <kracor@xxxxxxxxxxx> wrote in message
news:C4Odndsu_7irjeDYnZ2dnUVZ_vGinZ2d@xxxxxxxxxxxxxx
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/CABCompressExtract.asp
Have you ever heard of or used this tool?
Bruce
"Stephany Young" <noone@localhost> wrote in message
news:u5NWR03GHHA.3676@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- WAS: Need some help...
- From: Bruce W. Darby
- Re: Need some help...
- From: Bruce W. Darby
- Re: Need some help...
- From: Bruce W. Darby
- WAS: Need some help...
- References:
- Need some help...
- From: Bruce W. Darby
- Re: Need some help...
- From: Stephany Young
- Re: Need some help...
- From: Bruce W. Darby
- Need some help...
- Prev by Date: Re: Need some help...
- Next by Date: Re: Best way to write to textfiles?
- Previous by thread: Re: Need some help...
- Next by thread: Re: Need some help...
- Index(es):
Relevant Pages
|