PowerBASIC Forums
  PowerBASIC Console Compiler
  Dir$

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   Dir$
Bob Westbrook
unregistered
posted July 27, 2002 05:36 PM           Edit/Delete Message   Reply w/Quote

Does dir$ work by reading the fat file?

Can it be used to compile directories as well as files?

If not is there a function that does?

Bob Westbrook

------------------

IP: Logged

Lance Edmonds
Member
posted July 27, 2002 07:49 PM     Click Here to See the Profile for Lance Edmonds     Edit/Delete Message   Reply w/Quote
IN PB/CC, DIR$ reports files, directories, and the volume label. However, it does not perform direct disk access - no Windows applications (ring-3) can or should.

That is, DIR$ uses the Windows API to operate. If you are after direct disk access, you might research using Ring-0 (ie, device driver or kernel-mode driver) to do it. Info on direct hardware and port access can be found at www.lvr.com

------------------
Lance
PowerBASIC Support
support@powerbasic.com

IP: Logged

Bob Westbrook
unregistered
posted July 28, 2002 06:25 AM           Edit/Delete Message   Reply w/Quote
Lance:

Using the dir$ exemplar in the help file, I don't see how one
get's directories and subdirectories.

Can you direct?

Bob

------------------

IP: Logged

Tom Hanlin
Member
posted July 28, 2002 07:20 AM     Click Here to See the Profile for Tom Hanlin     Edit/Delete Message   Reply w/Quote

#INCLUDE "win32api.inc"
FUNCTION PBMAIN
CHDRIVE "c"
CHDIR "\"
mask$ = "*.*"
f$ = DIR$(mask$, %subdir)
WHILE LEN(f$)
PRINT f$
f$ = DIR$
WEND
WAITKEY$
END FUNCTION

See Samples\Util\FileFind.bas for fancier work.

------------------
Tom Hanlin
PowerBASIC Staff

IP: Logged

Eros Olmi
Member
posted July 28, 2002 01:08 PM     Click Here to See the Profile for Eros Olmi     Edit/Delete Message   Reply w/Quote
Tom,

in your example, DIR$ returns both directories and files.
Is there a way to get directories only without using getattr?

Regards


------------------
Eros Olmi
erosolmi@libero.it

[This message has been edited by Eros Olmi (edited July 28, 2002).]

IP: Logged

Mel Bishop
Member
posted July 28, 2002 01:34 PM     Click Here to See the Profile for Mel Bishop     Edit/Delete Message   Reply w/Quote
quote:
Originally posted by Eros Olmi:
Is there a way to get directories only without using getattr?

For each DIR$ envoked, check the attribute bit. I can't remember
which bit it is but if the DIR$ is a directory, the bit will be
set.

Normally, a directory will have an attribute of 16. The function
"t = attrib(te$)" may return 16 or may not. If the folder is
hidden or other attributes are attached, the value will be
different. It's best to go ahead and check the binary string
of the value returned.

------------------

IP: Logged

Lance Edmonds
Member
posted July 28, 2002 01:44 PM     Click Here to See the Profile for Lance Edmonds     Edit/Delete Message   Reply w/Quote
Filenames of "regular" files are always returned, in addition to those with the specified attribute.

See "DIR$ function" in the doc's for more information.

To filter out directories, use a simple bitwise evaluation within the loop:


' %SUBDIR = 16 is defined in WIN32API.INC
f$ = DIR$(...)
DO
IF (GETATTR(f$) AND %SUBDIR) THEN ' f$ names a sub-directory
...
END IF
f$ = DIR$
LOOP

------------------
Lance
PowerBASIC Support
support@powerbasic.com

IP: Logged

Tom Hanlin
Member
posted July 28, 2002 04:13 PM     Click Here to See the Profile for Tom Hanlin     Edit/Delete Message   Reply w/Quote
You may also wish to screen out the virtual directories, "." and "..".
Check for them by exact name, since it's quite valid for a filename to
start with ".", these days.

------------------
Tom Hanlin
PowerBASIC Staff

IP: Logged

Bob Westbrook
unregistered
posted July 31, 2002 01:41 PM           Edit/Delete Message   Reply w/Quote
f$ = DIR$(mask$, %subdir)

The %subdir feature here returns all of the files AND directories
as 16. Makes it a little hard to tell one from the other.

I installed the Getattr feature and it returns the attr correctly.

I'm curious the image.dat file returns an attr of 33. Not listed
in the help file.

What is 33?

Bob

------------------

IP: Logged

Bob Westbrook
unregistered
posted July 31, 2002 02:07 PM           Edit/Delete Message   Reply w/Quote
using the getattr function on my c:\ directory, I note that
a system file setuplog.txt is being returned as a 16 attribute.

Clearly not a directory. Is there a way to get around this?

Bob

------------------

IP: Logged

Tom Hanlin
Member
posted July 31, 2002 02:17 PM     Click Here to See the Profile for Tom Hanlin     Edit/Delete Message   Reply w/Quote
As explained in the help file, attributes are additive. That's why
Lance's example uses AND to test for a specific flag. 33 decomposes
to 32 (%ARCHIVE) + 1 (%READONLY).

16 (%SUBDIR) will never be returned for anything but a subdirectory.
Look for a bug in your code. Make sure you're not leaving the parentheses
off of the IF condition, here: you need the bitwise AND, not the Boolean AND,
as explained in the help file under IF.

That is, gotta be this:

IF (GETATTR(f$) AND %SUBDIR) THEN

Not this:
IF GETATTR(f$) AND %SUBDIR THEN

------------------
Tom Hanlin
PowerBASIC Staff

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c