Announcement

Collapse
No announcement yet.

Listing files, whats wrong with this?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listing files, whats wrong with this?

    This is a cut-down version of "findfile.bas" (from the PB FTP area). Findfile finds certain files and lists size, etc etc and is
    All I want to do is list all files (and subdirs and subfiles) in any specified directory, so ive made a cut-down version called "listfile.bas".
    It behaves strangely though and I can't see why?

    Code:
    $CPU 8086           ' program works on any CPU
    $COMPILE EXE              ' compile to an EXE
    $ERROR ALL OFF            ' turn off error handling
    $STRING 8                 ' set largest string size at 8k
    $STACK  16384             ' use a 16k stack
    $OPTION CNTLBREAK OFF     ' don't allow Ctrl-Break to exit program
    $INCLUDE "PB35.INC"       ' link library
    DEFINT A-Z                ' default all variables to integers for maximum
                              ' speed and minimum size
    
    EXIT FAR AT FarExit                                  'to exit all recursion
    StartPath$ = "c:\temp"                              'get the default drive
    FileSpec$  = "*.*"                                   'get the search filespec
    ListFiles StartPath$, FileSpec$                      'do the search
    FarExit:                                             'for EXIT FAR
    END
     
    SUB ListFiles(StartPath AS STRING, FileSpec AS STRING) PRIVATE
      DIM OldDtaBuffer AS STRING
      DIM DtaSeg       AS INTEGER
      DIM DtaOfs       AS INTEGER
      DIM CurrPath     AS STRING
      DIM Tmp          AS INTEGER
      GetDTA DtaSeg, DtaOfs
      DEF SEG = DtaSeg
        OldDtaBuffer = PEEK$(DtaOfs, 44)    'save current DTA information
      DEF SEG
      STDOUT StartPath$
      FileName$ = DIR$(StartPath$ + "*.*", 55)
      WHILE LEN(FileName$) > 0
          STDOUT "FILE=" & StartPath$ & FileName$
          IF (DtaAttrib = 16) AND (ASCII(FileName$) <> 46) THEN
            ListFiles StartPath$ + FileName$ + "\", FileSpec$
          ELSEIF WildMatchFile(FileName$,FileSpec$) THEN
          END IF
          IF INKEY$ = CHR$(27) THEN   'is escape is pressed
            EXIT FAR
          END IF
          FileName$ = DIR$            ' find next
      WEND
      DEF SEG = DtaSeg
        POKE$ DtaOfs, OldDtaBuffer$   'restore saved DTA information
      DEF SEG
    END SUB
    Or, does anyone have any working PBDOS source that simply lists all files in a specified directory?
    Thankyou muchly!


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

  • #2
    Greetings Wayne!

    I don't know if this will help you; but, this kind of programming is at my level and I can assist if needed.

    Wayne:
    ...so ive made a cut-down version called "listfile.bas"...It behaves strangely though and I can't see why?
    I'm not sure what you mean when you say that it behaves strangely; but, I did notice that your output is missing one slash which can be easily added in like this:

    Code:
    StartPath$ = "c:\temp\"
    ...it doesn't affect the program adversely; but it does change the output text. I also noticed that things are quite sorted the way they should. Seemingly, the output should be something like this:

    Code:
    Start Directory (Dir1)
     Files within the directory (Dir1)
    Next Directory (Dir2)
     Files within that directory (Dir2)
    Next Directory (Dir3)
     Files within that directory (Dir3)
    ...
    ...but instead, I was given:

    Code:
    Start Directory (Dir1)
     Files within the directory (Dir1)
    Next Directory (Dir2)
     Files within that directory (Dir2)
    Next Directory (Dir3)
     Files within that directory and the start directory (Dir3 and Dir1)
    ...
    Wayne:
    Or, does anyone have any working PBDOS source that simply lists all files in a specified directory?
    I have easily workable code, for me, that returns the files under the directory--refer to DIR$ in the help file, though it doesn't take care of recursing the subdirectories. I kind of like the code presented and it could probably be edited into something fairly handy.

    If I was to use this code, I would ditch the line "STDOUT StartPath$" and replace the line "STDOUT "FILE=" & StartPath$ & FileName$" with an entry to an array with that element. I would then sort the array to be sure things are nice and neat and then I could easily list them in whatever fashion I like or search for specific files within my array.


    ------------------
    Don Ewald
    mailto:[email protected][email protected]</A>
    Donnie Ewald
    [email protected]

    Comment


    • #3
      Greetings Don,
      Adding a slash on the end fixed it - I thought I had already tried that though I mustve broken other code at that stage also
      Thanks for your help!


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

      Comment

      Working...
      X