DIR isnt working?

New to FreeBASIC? Post your questions here.
Post Reply
Rainwulf
Posts: 35
Joined: Mar 28, 2007 11:33

DIR isnt working?

Post by Rainwulf »

In 20beta, print dir ("*", fbdirectory) returns "." then ".." then the actual files in in the directory instead of directories.

Its like fbdirectory is &HFF but i have tested it, and its correct. &h10.

No idea whats going on....
Any ideas?
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

The directory flag doesn't specify that only directories be returned; it just *allows* directories to be returned.
But, you can optionally pass an "attributes" byref parameter, that will be set to the attributes of the file. If those attributes have the fbDirectory bit set, then you know it's a folder.
Try this program. It should return both directories and normal files:

Code: Select all

#include "dir.bi"

dim as integer attrs
dim as string d = dir( "*", (fbNormal or fbHidden or fbSystem or fbDirectory), attrs )

do while len(d)
    if (attrs and fbDirectory) <> 0 then print "Directory", else print "File",
    print d
    d = dir( attrs )
loop
Check out the Dir manual page for more information. The second example there is also pretty thorough:
http://www.freebasic.net/wiki/KeyPgDir

Admittedly, I'm surprised that it's returning any files though, since they usually have the Archive attribute set, and they won't be returned if you're just passing fbDirectory.
Post Reply