If I understand what you are trying to achieve correctly then you have a
folder structure that resembles;
C:\Top
Sub1
SubSub11
SubSub12
SubSub13
Sub2
SubSub21
SubSub22
SubSub23
Sub3
SubSub31
SubSub32
SubSub33
and what you want to end up with is a struncture that resembles:
C:\Compress
Sub1.cab
Sub2.cab
Sub3.cab
If that is the case then you logic is a bit flawed. The line
'i_Compress.Com pressFolder(str TargetDir, strFinalFile, "", 0)' should
probable read 'i_Compress.Com pressFolder(_Fo lder, strFinalFile, "", 0)'.
Apart from that, 7 out of 10 and here are your notes: :)
Dim strSourceDir As String = txtSelectDir.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
These 2 lines are completely redundant. Their values are seldom referred to
and never modified therefore the values can be used directly from the
TextBox controls. Before proceeding, I would be inclined to trim the content
of both TextBoxes to ensure that any leading and/or trailing whitespace,
that may be present, is removed. You may also like to add some validation to
ensure that values have been entered and the values entered are, in fact,
valid.
prbProgress.Min imum = 0
Unless you mave modified the value of prbProgress.Min imum elsewhere in your
app, (which is probalbly unlikely) then there is no need to set it here
because it is already 0. However, it is more likely that you have used the
ProgressBar elsewhere in you app so it is important to make sure that it
starts it's counting from 0 by resetting the value of prbProgress.Val ue.
prbProgress.Max imum = CInt(_Folders.L ength)
The Length property of an array returns an Integer so there is no need to
carry out any conversion when assigning it to any other object that is also
an Integer.
The Path.GetFileNam e(strFldr2Compr ess) in the 2nd line of the loop is, at
the least, redundant, but more importantly it is downright confusing. The
first line of the loop get the last node of the folder name and stores it in
a variable. To do carry out the operation again on the variable is
absolutely not necessary.
Now we can note that the only time that strFldr2Compres s is used is in the
very next line and therefore the use of an interim variable is not
necessary.
Dim i_Compress As CabLib.Compress = New CabLib.Compress ()
In VB.Net this can be shortened to 'Dim i_Compress As New CabLib.Compress '.
Also, the instantiation of i_Compress is being carried out on every
iteration of the loop, whereas it only needs to carried out once.
lblProgress.Tex t = ("Compressin g: " & strFinalFile)
At the point that this is executed the compression operation has already
finished so this line should appear earlier in the loop.
At the 2 points where UI elements are 'updated', the app is in a faily tight
loop and you may find that the ProgressBar and/or Label do not 'update' as
you might expect them to. A couple of forced updates will be of assistance
here to allow the UI Elements to repaint in a timely manner.
The modified method is shown below:
Private Sub CompressFolder( )
txtSelectDir.Te xt = txtSelectDir.Te xt.Trim()
txtWriteDir.Tex t = txtWriteDir.Tex t.Trim()
Dim _folders As String() = Directory.GetDi rectories(txtSe lectDir.Text)
prbProgress.Val ue = 0
prbProgress.Max imum = _folders.Length
prbProgress.Ste p = 1
Dim _compress As New CabLib.Compress
For Each _folder As String In _folders
Dim _finalfile As String =
Path.ChangeExte nsion(Path.Comb ine(txtWriteDir .Text,
Path.GetFileNam e(_folder)), "cab")
lblProgress.Tex t = ("Compressin g: " & _finalfile)
lblProgress.Upd ate()
_compress.Compr essFolder(_fold er, _finalfile, "", 0)
prbProgress.Per formStep()
prbProgress.Upd ate()
Next
End Sub
As you can see, it is now a bit leaner without the redundant variables and
with the loop having no extraneous logic in it.
Although I invariably use hugarian notation for names of controls as you
have done, (even if you didn't know you were doing it), I like to use
lowercase with a preceding underscore for naming all local variables. I find
that this gives me continual visual prompts as to the scope of objects.
Of course, all this is my opinion, and you should code in a style that suits
you.
Have fun dissect that lot :)
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
Stephany,
I owe you a debt of gratitude. With your assistance, I was able to find a
way to do what I wanted to do, even though I don't consider myself a
developer by any mean's. I now have something I can take to work and use
to make things a bit easier on my techs. While I doubt that the coding is
all that elegant, here is the final sub that I was able to come up with
that is doing the job I need it to do. Again, thanks for all the
assistance. Happy Holidays.
Private Sub CompressFolder( )
Dim strSourceDir As String = txtSelectDir.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)
prbProgress.Min imum = 0
prbProgress.Max imum = CInt(_Folders.L ength)
prbProgress.Ste p = 1
For Each _Folder As String In _Folders
Dim strFldr2Compres s As String = Path.GetFileNam e(_Folder)
Dim strFinalFile As String =
Path.ChangeExte nsion(Path.Comb ine(strTargetDi r, _
Path.GetFileNam e(strFldr2Compr ess)), "cab")
Dim i_Compress As CabLib.Compress = New CabLib.Compress ()
i_Compress.Comp ressFolder(strT argetDir, strFinalFile, "", 0)
prbProgress.Per formStep()
lblProgress.Tex t = ("Compressin g: " & strFinalFile)
Next
End Sub
"Stephany Young" <noone@localhos twrote in message
news:e1******** ******@TK2MSFTN GP06.phx.gbl...
>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.