Need some help...

S

Stephany Young

So you've found that there's nothing more sobering than looking at code you
have written yourself and saying, 'What idiot wrote this rubish?'. :)


That's much betterer now ... but a couple of notes.

You are making 2 calls to the Path.GetFileName() method with the same
parameter, to get the name of the deepest node of the folder path. I my view
it is better to call that method once, store the result in a local variable
and use that when you need to:

Dim _deepestnode As String = Path.GetFileName(_Folder)
 
B

Bruce W. Darby

Christmas shopping almost finished.... :)


Stephany Young said:
So you've found that there's nothing more sobering than looking at code
you have written yourself and saying, 'What idiot wrote this rubish?'. :)

And nothing more sobering than doing it 5 minutes after you post a EUREKA!
on the newsgroup. :)
You are making 2 calls to the Path.GetFileName() method with the same
parameter, to get the name of the deepest node of the folder path. I my
view it is better to call that method once, store the result in a local
variable and use that when you need to:

A logical conclusion and one which I shall take to heart.
You then don't need the local variable strFinalFile and the line where
that is used becomes:

i_Compress.CompressFolder(_Folder,
Path.ChangeExtension(Path.Combine(strTargetDir, _deepestnode), "cab"), "",
0)

This won't work. I've already tried it. Not sure why but it gives me an IO
error stating that I'm passing too many variables.
The instantiation of i_Compress is still inside the loop. This will cause
unecessary overhead and should be moved to a point before the start of the
loop. Think of it like making a cup of coffee and leaving it on the beench
of your kitchen. Every time you want a sip you have to go out to the
kitchen and then return to your office. I'm sure that you would consider
that to be a waste of your resources (time and effort).

Now, to make sure I've got this down... The line stating Dim i_Compress as
New CabLib.Compress should occur on any line OUTSIDE the start of the
For...Next loop, but the actual line stating i_Compress.CompressFolder...
should be on a line INSIDE the loop?
Onward and upward :)

As Mork would have stated.... Nanoo...Nanoo... :) Sorry, can't do the
spreadfingered handshake here... might get me arrested. :)
 
S

Stephany Young

Yes ... But I would term it 'BEFORE the start of the loop' rather than
'OUTSIDE the start of the loop' which could also include after the end of
loop (for those that are picky).

And yes, the actual call to i_Compress.CompressFolder MUST be inside the
loop.

I don't understand why the call to i_Compress.CompressFolder is not working.
It takes 4 parameters and they are:

_Folder,
Path.ChangeExtension(Path.Combine(strTargetDir, _deepestnode), "cab")
""
0

The 1st parameter is the source folder.

The 2nd parameter is the name of the resultant .cab file.

The 3rd parameter is a filter for dealing only with a subset of files. ""
(empty string) means don't filter.

The 4th parameter is for limiting the size of any one .cab file. 0 (zero)
means don't limit.

Directly before that line you can throw in:

Console.WriteLine(_Folder)
Console.WriteLine(Path.ChangeExtension(Path.Combine(strTargetDir,
_deepestnode), "cab"))

and then you can make sure that the values are as expected. (Make sure you
run it from the IDE and the results will be displayed in the Output window).
 
T

Tom Leylan

Possibly a good time to introduce the debugger... if you are going to
monitor code take the opportunity to see how breakpoints, watchpoints, step
and trace work.
 
B

Bruce W. Darby

Tom,

The only one of these tools that I haven't used is the trace. Without the
other three, I'd have been pulling my hair out by the handful... and I'm
already bald! :) I'll take a look into the trace tool tomorrow, if I can get
back to the keyboard. :) Thanks again.
 
B

Bruce W. Darby

Stephany Young said:
I don't understand why the call to i_Compress.CompressFolder is not
working. It takes 4 parameters and they are:

The second parameter is what causes the failure. It is somehow not seeing
that I'm attempting to pass 'one' simple parameter. I'm thinking that it's
catching the commas in the Path.Combine method and thinking that it's
getting five or six parameters rather than four. In software testing terms,
I'd say that was a bug. LOL

Example:
Param 1 - _Folder,
Param 2 - Path.ChangeExtension(Path.Combine(strTargetDir,_deepestNode),
Param 3 -"cab:),
Param 4 - "",
Param 5 - 0
 
T

Tom Leylan

If nothing else I believe you are missing a "." as in ".cab" in the
Path.Combine method. Trust the compiler it isn't confused by commas :) It
is precisely the lack of ambiguity in a language that makes it all work.
 
T

Tom Leylan

Well normally I test these things before posting but this time I just read
the docs. After I tested it, it appears to work whether one includes the
dot extension separator or not but given the documentation says it should
include the dot I would make a habit of it.

What I would suggest is that you break this line apart:
Path.ChangeExtension(Path.Combine(strTargetDir,_deepestNode), ".cab") to see
what the results are in the two methods (you can recombine them after you
see it works.

So try something similar to this (may have been suggested already) to see if
you get the results you expect.

debug.writeline(strTargetDir)
debug.writeline(_deepestNode)
debug.writeline(Path.Combine(strTargetDir,_deepestNode))
debug.writeline(Path.ChangeExtension(Path.Combine(strTargetDir,_deepestNode),
".cab"))

If everything looks okay I'd suggest you run through the loop you have but
don't call i_Compress.CompressFolder() just comment that for now. Just
output the results of the path methods instead so you can see if one of them
is malformed. Besides that you should post what IO error you received
(those are clues.)

Is there a possibility you have need to trim the values you're getting from
the textbox? If there are trailing blanks anywhere they would be combined
into the final path and that one isn't likely to exist.
 
S

Stephany Young

Typo!!!!!

Directly following the b of cab should be a " - you have a :

FYI, I get the impression that you are typing your code into the message
rather than copying and pasting it. If you are then it is too open to typo's
etc. and we are scratching our heads to figure out how you even managed to
compile it etc.

When you do copy and paste code from the IDE into a message it may look like
a load of rubbish. Simply do a Format/Rich Text (HTML) from the menu and
then do a Format/Plain Text and it will look OK.

Now the big question is, what result do you get when you execute?:

Console.WriteLine(Path.ChangeExtension(Path.Combine(strTargetDir,
_deepestnode), "cab"))
 
B

Bruce W. Darby

Well, I'm not attempting to be argumentative, but in reading up in the
Path.Combine method, it states that if a period is not included in the
extension path, then it automatically includes it. I'm not in any way trying
to fault the compiler.
 
B

Bruce W. Darby

Stephany,

I'm far too lazy to type that much code into a newsgroup window... LOL Trust
me when I say that I've made prodigious use of the Ctrl-C/Ctrl-V option.

Now on with the show...

When I commented out the i_Compress.CompressFolder line and used your
Console.Writeline command line, I got a string of text showing the path of
the compressed file, as follows

strSourceDir "C:\Program Files\Corel\Corel Paint Shop Pro X" String
strDeepestNode "C:\Program Files\Corel\Corel Paint Shop Pro X\Brushes"
String

But I went just a little bit further and changed the Console.Writeline
portion of the command line to i_Compress.CompressFolder. As soon as I left
that line, three errors popped up in the IDE. Here they are...

Error 1 Argument not specified for parameter 's_CabFile' of 'Public Sub
CompressFolder(s_Folder As String, s_CabFile As String, s_Filter As String,
s32_SplitSize As Integer)'. D:\Program Files\Microsoft Visual
Studio\Projects\Folder Archive\Folder Archive\Folder Archive\Form1.vb 129 13
Folder Archive

Error 2 Argument not specified for parameter 's_Filter' of 'Public Sub
CompressFolder(s_Folder As String, s_CabFile As String, s_Filter As String,
s32_SplitSize As Integer)'. D:\Program Files\Microsoft Visual
Studio\Projects\Folder Archive\Folder Archive\Folder Archive\Form1.vb 129 13
Folder Archive

Error 3 Argument not specified for parameter 's32_SplitSize' of 'Public Sub
CompressFolder(s_Folder As String, s_CabFile As String, s_Filter As String,
s32_SplitSize As Integer)'. D:\Program Files\Microsoft Visual
Studio\Projects\Folder Archive\Folder Archive\Folder Archive\Form1.vb 129 13
Folder Archive

These are the same errors I was receiving when I tried what you suggested,
which is why I believe that there may be a bug in the .dll because it's
(possibly) parsing the command strings only for commas and when it sees one,
it goes looking for the next piece of the puzzle instead of trying to make
sure the piece I've provided it really fits. When I present it with just a
variable it behaves as it should. :)

P.S. In the last message I posted with the leading params, I did make a
typo, but I was trying to illustrate how I thought the .dll was parsing it's
commands and got in a rush and just typed stuff in. The actual code doesn't
have that colon at the end of "cab". Sorry.
 
L

Lucian Wischik

Bruce W. Darby said:
These are the same errors I was receiving when I tried what you suggested,
which is why I believe that there may be a bug in the .dll because it's
(possibly) parsing the command strings only for commas and when it sees one,
it goes looking for the next piece of the puzzle instead of trying to make
sure the piece I've provided it really fits. When I present it with just a
variable it behaves as it should. :)

I remember looking at source code for an infozip dll. (or was it
pkzip? gzip? I forget). What they did for the DLL interface was to
take the arguments, construct a command-line text string out of them,
and pass this string to the zip libraries main() routine (which
obviously had been written as a standalone console program).

Also I've been using the command-line utility "mplayer" recently which
simply fails to work when given filenames that include commas.


I haven't been following the details of this thread. But what you
describe is not beyond the bounds of possibility, depending on how
lazy/inelegant the developers of your DLL were.
 
S

Stephany Young

Yes. There are few things about the documentation for the
Path.ChangeExtension method that, at first reading, appear to be
contradictory. When one reads it carefully, it turns out that the
contradictions are really ambiguities.

For instance, one might expect:

Console.WriteLine(Path.ChangeExtension("abc.def", ""))
Console.WriteLine(Path.ChangeExtension("abc", ""))

to produce:

abc
abc

However it actually produces abc. in both cases.

The paremeter can have a trailing . and the second parameter can have a
leading . and the method will work out what to do:

Console.WriteLine(Path.ChangeExtension("abc.def", ".ghi"))
Console.WriteLine(Path.ChangeExtension("abc.", "ghi"))
Console.WriteLine(Path.ChangeExtension("abc", ".ghi"))
Console.WriteLine(Path.ChangeExtension("abc", "ghi"))

all produce the same result.

When presented with ambiguities and/or contradictions in the documentation I
generally run some tests to see what actually happens. I also find Lutx
Roeder's Reflector, (http://www.aisto.com/roeder/dotnet/), very useful for
having a look at the internals of various things.
 
S

Stephany Young

Another Paint Shop Pro X user. That makes 2 I know of now. :)

I would expect strDeepestNode to have a value of Brushes rather than the
full path, because strDeepestNode is assigned the result of
Path.GetFilename(_Folder).

If strTargetDir is "C:\Temp" then I would expect the result of
Path.ChangeExtension(Path.Combine(strTargetDir, strDeepestNode), "cab") to
be "C:\Temp\Brushes.cab".

What happens if you use paths that don't have any spaces in them?

It's possible that the CabLib library has a 'bug' in it but I would be
inclined to make sure that I am sure that my own code is correct and what
the behaviours are before I start going down that path.?
 
B

Bruce W. Darby

Stephany & Tom,

Here is the latest iteration of my sub that you both have been so kind as to
work with me on. In this format, the sub works perfectly...

Private Sub CompressFolder(ByVal strSourceDir As String, ByVal strTargetDir
As String)
Dim strFolders As String() = Directory.GetDirectories(strSourceDir)
prbProgress.Maximum = strFolders.Length
prbProgress.Step = 1
prbProgress.Visible = True
lblProgress.Visible = True
Dim i_Compress As New CabLib.Compress
For Each strFolder As String In strFolders
Dim strDeepestNode As String = Path.GetFileName(strFolder)
Dim strFinalFile As String = Path.ChangeExtension(Path.Combine(strTargetDir,
_
strDeepestNode), ".cab")
lblProgress.Text = "Compressing: " & strDeepestNode
lblProgress.Update()
i_Compress.CompressFolder(strFolder, strFinalFile, "", 0)
prbProgress.PerformStep()
prbProgress.Update()
Next
prbProgress.Visible = False
lblProgress.Visible = False
End Sub

You both have been so very kind to put up with me and my coding and I shall
truly appreciate that, even when I start to grow as a developer (should THAT
ever happen) :) I know that I have a lot to learn, but I'm moving as fast as
I can most of the time and the time I get to code actually comes out of my
discretionary time at the end of the day. Call that, my own time. hehehe But
it's an opportunity for me to learn from those who have a better grasp than
I on the intracacies of the language and I want you to know that I'm not
going to stop, no matter how slowly I move. Perhaps someday I'll know enough
to give something back to the community.

Happy Holidays,
Bruce
 
B

Bruce W. Darby

Stephany,

I'm going to hold out my wrist and let you slap it, OK?? You are correct. I
had temporarily changed the
Path.GetFilename(_Folder) to simply '= _Folder' to try something after
reading one of your messages. When I noted that it was providing the full
path, I changed it back to the original. But I mada the copy of the line
prior to changing it back without realizing that I would throw everything
out of whack. Told you I was senile. :) I posted the working sub under your
other response earlier.
 
C

Cor Ligthert [MVP]

Bruce,

In my idea are you too much ironing. In this case it is in my idea better to
carpenter a small project where only the problems are in.

In that way you can more easily eliminate the things that are going wrong to
come to the right result.

(Almost the same advice as Tom gave in another question this night (for
me)).

Cor
 
S

Stephany Young

Let me get my black leather basque and thigh boots on and let me grap my
whip.

'You know what happens to naughty boys don't you!!!!!!!!!!'

Now we've got the punishment out of the way, are you saying that:

i_Compress.CompressFolder(strFolder,
Path.ChangeExtension(Path.Combine(strTargetDir, strDeepestNode), ".cab"),
"", 0)

still doesn't work and that:

Dim strFinalFile As String =
Path.ChangeExtension(Path.Combine(strTargetDir, strDeepestNode), ".cab")
i_Compress.CompressFolder(strFolder, strFinalFile)

does work?

If that is the case then I'll fall off my chair because it worked for me
even with space charactes in the paths.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top