bug in File>>for:in:do:?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

bug in File>>for:in:do:?

Jochen Riekhof-6
Hi...

When I specify e.g. '*.txt' as matchString in File>>for:in:do:, I get
also all files with a longer extension, e.g. '*.txt2'. Can it be that
this is a bug?
Here is some sample code that you can execute inside a workspace. It
writes a dir to your temp directory. You can clean it up using
File deleteDirectory: dir.

What do you think?

Ciao

...Jochen


"set up paths"
dir := File composePath: File tempPath subPath: 'dolphinbug'.
file := File composePath: dir stem: 'file' extension: 'txt'.
file2 := File composePath: dir stem: 'file2' extension: 'txt2'.
file_a := File composePath: dir stem: 'file_a' extension: 'txt_a'.
"create dirs and files"
File createDirectory: dir.
[(s := FileStream write: file) nextPutAll: 'file content'] ensure: [s
close].
[(s := FileStream write: file2) nextPutAll: 'file2 content'] ensure: [s
close].
[(s := FileStream write: file_a) nextPutAll: 'file_a content'] ensure:
[s close].
"demonstrate error"
Transcript show;clear.
File for: '*.txt' in: dir do: [ :each | Transcript print: each
cFileName;cr].


Reply | Threaded
Open this post in threaded view
|

Re: bug in File>>for:in:do:?

Peter Kenny-2
"Jochen Riekhof" <[hidden email]> wrote
>Can it be that this is a bug?

Jochen

Weird. Your test case performs as you say on my XP system. It looks as
though the Windows utility is doing the wild card matching wrong. It goes
very wrong if you have the * wild card, but is also odd if you use the ?
wild card.

I have no explanation, but a possible work round. In your example, if you
put the match string as '??????.txt', it only matches the first file (i.e.
file.txt). It looks as though a match string with n occurrences of ?
followed by '.txt' will match any file whose name is /up to/ n characters
followed by the exact extension. If you can specify the maximum length of
your file names, this might give you a way of doing what you want.

Hope this helps

Peter Kenny


Reply | Threaded
Open this post in threaded view
|

Re: bug in File>>for:in:do:?

Jochen Riekhof-6
Hi Peter...

thank you for your nice workaround! Fortunately in my case it was just
an accident to find this out, I needed some sample files with different
extensions as I did not have the real files at hand, and so just renamed
txt to txt2. The originals have different 3-char extensions.

Weird bugs in pattern matching anyway, I remember that ? was for exactly
one char, not one or zero chars. I saw ?*.txt e.g. to ensure .txt files
were not found.

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: bug in File>>for:in:do:?

Chris Uppal-3
In reply to this post by Jochen Riekhof-6
Jochen,

> When I specify e.g. '*.txt' as matchString in File>>for:in:do:, I get
> also all files with a longer extension, e.g. '*.txt2'. Can it be that
> this is a bug?

Some kind of Windows weirdness, I think (Win2K and WinXP).  Have you noticed
that if you try '*.tx' (without the last 't') then the loop doesn't match
anything ?  Also if you have file.c and file.cpp, then '*.c' only matches the C
file.  But, if you have file.htm and file.html, then '*.htm' matches both of
them...

Wonderful!

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: bug in File>>for:in:do:?

Jochen Riekhof-6
Hi Chris...

> Wonderful!

I wouldnt be surprised if this is still caused by ancient 8.3 filename
legacy code or compatibility issues. Wonderful indeed!

Ciao

...Jochen


Reply | Threaded
Open this post in threaded view
|

Re: bug in File>>for:in:do:?

hboon@motionobj.com
In reply to this post by Chris Uppal-3
This happens because the wildcard matching checks for long and short
file names. Try doing a dir /x in the test directory and you'll see
that files such as xxx.html will have a short file name like
3891SXF.HTM which explains the discrepancy between matching of .c and
.html.

--
HweeBooni