dir$ problem listing all files?

F

Fredrated

using dir$ I don't seem to get all of the files in a director.

in the folowing loop, dir$ gives me 37,184 files, but windows explorer
directory properties says there are 37,315 files.
(These files are stored in one directory by a commercial application, I have
no control over this)

CODE:
strFile = Dir$(strDir)
rs.AddNew
rs!Filename = strFile
rs.Update

Do While True

strFile = Dir$()
If strFile = "" Then GoTo Done

rs.AddNew
rs!Filename = strFile
rs.Update

Loop

Done:
etc. etc.
ENDCODE

A (possibly related) problem is that windows explorer can't seem to list all
the files in name order, perhaps because there are too many to handle
properly?

For example, the following is a typical section of the directory list, in
name order:
2nd 15 E 4Th (13)1.jpg
02-Right fender1.JPG
3-18-03ACK1.doc
03 View of trees1.jpg
3KubicACK1.doc
03-Right door1.JPG

Any suggestion are welcome, since we are about to ditch this application. I
am in the process of trying to determine the completeness and accuracy of the
data, but things like the dir$ problem and the seemingly odd behavior of the
directory list are getting in the way.

Any suggestions greatly appreciated, thanks in advance for any help.

Fred
 
J

Jack Leach

Two things to look at: first, I think you may be nearing the limit for the
number of files allowed in a folder. I'm not positive, but I think you're
close.

Also, have you checked for hidden/system files? The second argument of the
dir function lets you define the types... you may get different results by
playing around with this (and depending on your system settings for explorer).

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
F

Fredrated

'Show hidded files' is selected in win explorer, so I think it is a file
limit problem.
I am going to copy 10,000 files into another directory and see if I can then
get better results.

By the way, DOS says I have 37,200 files!

Thanks for your reply.

Fred
 
J

Jack Leach

'Show hidded files' is selected in win explorer, so I think it is a file
limit problem.

I guess my point here was, if explorer is showing more files than Dir, and
you happen to be showing hidden/system files in explorer, there's a good
chance the Dir function is only returning the non-hidden files (as I believe
it's defaulted to do when no arguments are supplied).

I would try working with the Dir filetype arguments to see if you can show
the difference of 131 files being hidden or system. I would think that a
filelimit error would have more drastic effects than what you are seeing.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
F

Fredrated

Sorry, I should have been a little more compete in my answer.

I am using "I:\Dorn\DOCS\*.*" as the initial DIR$ argument.
Are there other arguments that can be used with Dir$?

Thanks

Fred


Is there
 
D

Dirk Goldgar

Fredrated said:
Sorry, I should have been a little more compete in my answer.

I am using "I:\Dorn\DOCS\*.*" as the initial DIR$ argument.
Are there other arguments that can be used with Dir$?


Have you considered looking it up in the online help?
 
J

Jack Leach

From the help file (type Dir and hit F1), it gives all arguments and their
descriptions.

Dir(pathname[, attributes])]

Pathname you already have, the attributes argument is the optional second,
which has to be an integer that is the sum of any of the given constants
(they do this so you can use more than one constant here). The windows file
attributes are as follows:

vbNormal = 0
vbReadOnly = 1
vbHidden = 2
vbSystem = 4
vbVolume = 8
vbDirectory = 16

So therefore, you can show Normal, Hidden, Readonly and System files all at
once by supplying the second argument as 7 (0+1+2+4)

Dir("C:\YourPath\", 7)

or

Dir("C:\YourPath\", vbNormal + vbReadOnly + vbHidden + vbSystem)

the help file is a highly underrated tool, and every keyword can be pulled
up by pressing F1 with the cursor on the right side of the word from within
the vba ide.

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
F

Fredrated

Thanks, I searched for arguments, only to confue the issue more.
no arguments returns files with no attributes, my original attempt.
adding vbHidden is supposed to add hidden files to the files with no
attributes.

However, adding vbHidden now returns even fewer files!

I am going to try another approach.
I will take the table of files referenced by the application and loop
through it, asking for each file if it exists in the directory with
If Len(Dir(Path & filename)) > 0 Then .... file exists in directory

If this works it should be good enough.

Thanks again.

Fred
 
D

Dirk Goldgar

Fredrated said:
Thanks, I searched for arguments, only to confue the issue more.
no arguments returns files with no attributes, my original attempt.
adding vbHidden is supposed to add hidden files to the files with no
attributes.

However, adding vbHidden now returns even fewer files!


I think you're doing something wrong in your code. However, there is one
wrinkle to using Dir(). In the midst of a Dir() loop, other calls to
Dir() -- other than the initial one and the one at the bottom of the loop to
get the next file -- will reset the search. That can confuse matters.
 

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