需要一些帮助... [英] Need some help...

查看:77
本文介绍了需要一些帮助...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是我的第一个VB.Net应用程序,它非常简单。但是

我的语法在某个地方遇到了麻烦。希望有人能指出我正确的方向。


历史:

我的工作涉及创建自定义包我们的高尔夫软件产品

购买我们软件的课程。课程数据保留为

,课程需要我们更换自定义文件。每个课程都有一个集中目录下的自己数据的
a文件夹。


问题:

自定义文件随着我们的客户基本增加,我们将成为一个严重的存储问题。


解决方案:

将每个课程文件夹压缩成一个单独的.cab文件,其中包含所有

课程的自定义文件,然后将这些文件存档到存储介质中,例如CD / DVD为



我需要帮助的地方:

我找到了一些实现命令行窗口并通过流传递一个

字符串的代码。正在实例化命令窗口,但是没有传递

字符串或者我运行makecab实用程序的语法是

off-base。我花了几个小时寻找示例代码,这将是解释makecab语法的原因。我还试图确定是否将

参数传入Sub正确。我已经在

行中休息了一下,字符串应该传递到命令窗口,但我不能

似乎从手表中获得了回复已经设定好了。我已经包含了一个

副本用于压缩文件的sub。如果这不是

正确的论坛,我会道歉。一个正确的方向轻推

将深受赞赏。


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)

/>
如果不是CompressProcess.HasExited那么


CompressProcess.Kill()


结束如果

stmStreamIn.Close()


stmStreamOut.Close()


stmStreamErr.Close()


结束次级

解决方案

不错的主意,但你的使用情况有点错误。

makecab.exe。


/ L开关只能用于将单个源文件压缩成

单个.cab文件,所以除非你想要gcillion的.cab文件不是很好。


/ F开关用于将多个源文件压缩成一个单个

..cab文件,但你认为它有点复杂。


Makecab.exe不使用standardinput / output。使用/ F开关,它从定义文件中读取所需的信息,除了创建.cab文件的
之外,还将摘要信息写入''报告''文件和

其他信息到''inf''文件。我甚至不考虑这些为什么和

为什么这样做因为你试图做的事情是轻微的

非标准与makecab.exe实际设计的相比。


现在为了细节。


你需要做的第一件事是写一个定义文件,让我们调用它

test.ddf用于练习:

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("。设置RptFileName = test.rpt")

_sw.WriteLine(" .Set Cabinet = ON&qu​​ot;)

_sw.WriteLine(" .Set Compress = ON&qu​​ot;)

Dim _files as String()= Directory.GetFiles(FromFolder)

Fo r每个_file作为字符串在_files

_sw.WriteLine(File.GetFileName(_ file))

下一页

_sw.Close()


如果你得到定义文件

的语法错误,Makecab.exe是非常无情的。


如果FromFolder确实如此不存在然后就会失败。


它将创建由ToFolder的最终节点指示的文件夹,但如果任何文件夹更高,它将失败
上层不存在。这个

可以通过执行来规避:


如果不是Directory.Exists(Path.GetDirectory(ToFolder))那么

目录.CreateDirectory(Path.GetDirectory(ToFold er))


请注意,.cab文件中所需的所有文件必须包含在

的定义中文件。正如您所看到的,通过在FromFolder中的所有文件迭代

可以轻松实现这一点。还要注意baecause .Set SourceDir

被指定,只需要实际文件名而不是完整路径。


接下来要执行makecab。 exe:


Process.Start(" makecab.exe"," / F test.ddf")。WaitForExit()


命令窗口会暂时出现并消失。


现在你可能想看看发生了什么。在

表单上输入一个TextBox,使其成为多行,将它的字体设置为您喜欢的单行间距字体

并将其调整到合适的大小。 />

TextBox1.Text = File.ReadAllText(" test.rpt")

现在你所要做的就是自己整理:


File.Delete(" test.ddf")

File.Delete(" test.inf")

档案.Delete(test.rpt)


如果你想查看test.inf文件,请按下File.Delete'

但是我怀疑它的内容是否会对你有什么价值,因为你想要实现的是什么。


以下链接会让你知道下载一个名为Cabsdk.exe的文件

其中包含一个Word文档,该文档提供了很多关于makecab.exe的详细信息。

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


玩得开心!

" Bruce W. Darby" < kr **** @ comcast.netwrote in message

news:bZ ************************** ****@comcast.com。 ..


这将是我的第一个VB.Net应用程序,它非常简单。但是

我的语法在某个地方遇到了麻烦。希望有人可以给我b $ b指向正确的方向。


历史:

我的工作涉及创建自定义包我们的高尔夫软件产品

购买我们软件的课程。如果课程需要我们替换他们的自定义文件,课程数据将作为备份保留

。每个

课程都有一个集中目录下的自有数据文件夹。


问题:

自定义随着我们的

客户群增加,文件将成为一个严重的存储问题。


解决方案:

压缩每个课程文件夹进入一个单独的.cab文件,其中包含所有

课程的自定义文件,然后将这些文件存档到存储介质

,如CD / DVD。


我需要帮助的地方:

我找到了一些实现命令行窗口并通过流传递一个

字符串的代码。正在实例化命令窗口,但是没有传递

字符串或者我运行makecab实用程序的语法

是非基础的。我花了几个小时寻找示例代码,这将是解释makecab语法的原因。我还试图确定是否将

参数传入Sub正确。我已经在

处将字符串传递到命令窗口的行中断了,但是我看起来似乎无法从手表中获得回复已经设定好了。我已经包含了我用于压缩文件的子副本。
如果这个

不是正确的论坛,我会道歉。正确的

方向的推动将深受赞赏。


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作为IO.StreamReader = CompressProcess.StandardOutput


Dim stmStreamErr作为IO.StreamRea der = CompressProcess.StandardError

stmStreamIn.Write(" makecab.exe / L%ToFolder %% FromFolder %% FinalFile%" &

System.Environment.NewLine)

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

/>
如果不是CompressProcess.HasExited那么


CompressProcess.Kill()


结束如果

stmStreamIn.Close()


stmStreamOut.Close()


stmStreamErr.Close()


结束子



Stephany,


谢谢你非常喜欢。我下班回家的时候会放手一搏。我已经下载了CabSDK的

链接,但是我没有看到.doc,所以

我会再次通过我的下载。干杯!


" Stephany Young" < noone @ localhostwrote in message

news:u5 ************** @ TK2MSFTNGP03.phx.gbl ...


不错的主意,但你使用

makecab.exe时,你的位置有点错误。



2006年12月9日星期六00:34:16 -0700,Bruce W. Darby写道:


这将是我的第一个VB.Net应用程序,它非常简单。但是

我的语法在某个地方遇到了麻烦。希望有人能指出我正确的方向。


历史:

我的工作涉及创建自定义包我们的高尔夫软件产品

购买我们软件的课程。课程数据保留为

,课程需要我们更换自定义文件。每个课程都有一个集中目录下的自己数据的
a文件夹。


问题:

自定义文件随着我们的客户基本增加,我们将成为一个严重的存储问题。


解决方案:

将每个课程文件夹压缩成一个单独的.cab文件,其中包含所有

课程的自定义文件,然后将这些文件存档到存储介质中,例如CD / DVD为



如果文件大小最重要,您可能需要考虑使用更好的压缩格式(rar,bzip等)。你可以使用sharpziplib完成

这类事情。

http://www.icsharpcode.net/OpenSourc...b/Default.aspx

-

Bits.Bytes
http://bytes.thinkersroom.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.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

解决方案

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(ToFold er))

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/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.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



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@localhostwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...

Nice idea, but you''re slightly on the wrong track with your usage of
makecab.exe.



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


这篇关于需要一些帮助...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆