Hi
I'm new to this grp. I'm working on Vb6.0 apps. Here i've a problem, I'm using Dir(filepath) to retrieve the file from specifies path and i want to retrieve similar files from the same folder. I wrote Dir$ in the end of while loop.

here is how my looks like

sDataFile = Dir$(sDataPath & sDataFile) ' first file
  Do While sDataFile <> ""
        sDataFile = Dir$ 'next matching file
  Loop

But this code retrieving unmatched file. Is there any limitation on the Dir() cmd..
Ex: There are files like abc2 03.txt, abc2 04.txt, abc20 03.txt, abc 20 04.txt.

If i enter abc20*.txt , it should return only last 2 files(abc20 03.txt, abc 20 04.txt) but its returning all 4 files.

Any help would be appreciated.

Thanks
Ramesh

Recommended Answers

All 7 Replies

Since your code looks correct the only thing I can think is that the OS you are on is forcing the 8.3 filename convention. This would result in spaces being removed from the name, thus making every file conform to the pattern abc20*.txt. I also note that your last file has a space after abc, leading me to the same conclusion

Regards

D

thanks for your reply. Any suggestions how to resolve this problem?

Regards
ramesh

Try naming those first two abc02. When using what I assume are dates on filenames you should always include leading 0s.

Since your code looks correct the only thing I can think is that the OS you are on is forcing the 8.3 filename convention.

Not likely since VB only works on $M Operating systems which don't have 8.3 limitations.

In that case the only thing I can think of is that the initial value for sDataFile is not being set to "abc20*.txt", hence the error is before the code listed

No, sDatafile is set to "abc20*.txt", but somehow its retrieving all 4 files. One workaround ot this problem is we have to input the filename as "abc20 *.txt, which returns last 2 files(abc20 03.txt,abc20 04.txt). But this is not similar to windows search.

Any help would b appreciated.

I think you've just run into one of the reasons us old-time programmers despise the addition of SPACE as a valid filename character -- even M$ can't figure out how to consistently handle the character. You may be out of luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.