home *** CD-ROM | disk | FTP | other *** search
- '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
- ' Msg#: 442 Date: 13 Apr 94 20:50:26
- ' From: Marty Duplissey Read: Yes Replied: No
- ' To: Chris Gauvin Mark:
- ' Subj: DIR
- '──────────────────────────────────────────────────────────────────────────────
- ' CG> I would like to know how to read files from a DIR < file.tst
- ' CG> into an array? Anybody?
- ' CG> Supressed Carrier
- 'Hear's a function I use in PDS. It won't work in QB but you can get some Ideas
- 'from it.
-
-
- FUNCTION dirarray% (Filespec$, Array$(), Flag%)
- '*****************************************************************
- '*Function | Dirarray% *
- '*Compiler | PDS 7.1,VBDOS 1.0 *
- '*Requires | Option Base 1,True,False,$Dynamic *
- '*Returns | True if file found False if not Found *
- '*Parameters| Filespec$: A valid filespec string to search on *
- '* | *
- '* | Array$: A string array to hold the file names *
- '* | Redimed internaly so no concern for size if Dynamic*
- '* | is enabled NOTE(Uses Redim Preserved Will not Work *
- '* | with QB) *
- '* | *
- '* | Flags%: An integer flag to tell if sorted or not *
- '* | 0 = Not sorted, 1 = Sorted by file name, 2 = Sorted*
- '* | by extension. Uses bubble sort for now make note *
- '* | to rewrite to QUICKSORT in the future. *
- '* | *
- '*Notes | REMEMBER this function sorts by string if using in *
- '* | a numerical environment ie Netmail you must resort *
- '* | accordingly. *
- '* | 03/04/94 Marty Duplissey *
- '*****************************************************************
-
- REDIM Array$(100)
- Array$(1) = DIR$(Filespec$)
- Pointer% = 2
- '*********************************************************
- '*Build array
- IF LEN(Array$(1)) THEN
- ok% = True
- DO UNTIL ok% = False
- Array$(Pointer%) = DIR$
- IF LEN(Array$(Pointer%)) = 0 THEN EXIT DO
- '*********************************************************
- '*Make Array Bigger if needed
- IF Pointer% = UBOUND(Array$, 1) THEN REDIM PRESERVE Array$(Pointer% + 100)
- Pointer% = Pointer% + 1
- LOOP
- REDIM PRESERVE Array$(Pointer% - 1)
- dirarray% = True
- ELSE
- dirray% = False
- END IF
-
- SELECT CASE Flag%
- CASE 0
- '*********************************************************
- '*Do nothing take array as it is
- CASE 1
- '*********************************************************
- '*Sorted by Filename
- Size% = UBOUND(Array$, 1)
- Done% = False
- DO UNTIL Done% = True
- Done% = True
- FOR A% = Size% TO 2 STEP -1
- IF Array$(A% - 1) > Array$(A%) THEN
- SWAP Array$(A% - 1), Array$(A%)
- Done% = False
- ELSE
- END IF
- NEXT A%
- LOOP
-
- CASE 2
- '*********************************************************
- '*Sort by extension
- Size% = UBOUND(Array$, 1)
- '*********************************************************
- '*Build index array to speed things up
- DIM ExtArray$(Size%)
- FOR A% = 1 TO Size%
- Pointer% = INSTR(Array$(A%), ".")
- IF Pointer% = 0 THEN Pointer% = LEN(Array$(A%))
- Length% = LEN(Array$(A%))
- ExtArray$(A%) = RIGHT$(Array$(A%), Length% - Pointer%)
- NEXT A%
- '*********************************************************
- 'Sort array and index array
- Done% = False
- DO UNTIL Done% = True
- Done% = True
- FOR A% = Size% TO 2 STEP -1
- IF ExtArray$(A% - 1) > ExtArray$(A%) THEN
- SWAP ExtArray$(A% - 1), ExtArray$(A%)
- SWAP Array$(A% - 1), Array$(A%)
- Done% = False
- ELSE
- END IF
- NEXT A%
- LOOP
- CASE ELSE
- PRINT "Invalid flag passed to Function (Dirarray%). Program is stopped"
- END
- END SELECT
- END FUNCTION
-