Announcement

Collapse
No announcement yet.

Directory listing

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

  • Directory listing

    I need to get a directory listing into a string format, or into an array either way, preferrably into a string format.

    I have two methods I am trying.
    The first is DIR$, but it returns the same file over and over again.
    The file is "C:\TEMP\*.*" and this is the contents of it and almost as I want to display it to the FTP Client:

    Code:
     Volume in drive C is TNG98      
     Volume Serial Number is <not shown>
     Directory of C:\TEMP
    
    .              <DIR>        03-27-00 10:13p .
    ..             <DIR>        03-27-00 10:13p ..
    DIR      TXT           990  03-27-00 10:13p DIR.TXT
    DIR2     TXT         2,097  03-27-00 11:25p dir2.txt
             2 file(s)          3,087 bytes
             2 dir(s)        2,108.52 MB free
    
    OK The first part returns the same filename 5 times, the second part re turns null.
    The first part is commented out as I tested part #2..
    
    '==============================================================================
    Function GetDirList(CurrentDir As String) Export As String
    Local hDir     As Long
    Local FindData As WIN32_FIND_DATA
    Local f        As Asciiz * 256
    Local x        As Long
    Local bytes    As Long
    Local sTmp     As String
    Local St       As String
    
    %DIR_LENGTH    = 5
    
    'For x = 1 To %DIR_LENGTH
    '    sTmp = Dir$(CurrentDir + "\*.*")
    '    If Len(sTmp) = 0 Then
    '       Exit For
    '    Else
    '        St = St + sTmp + $CRLF
    '    End If
    'Next
    
    For x = 1 To %DIR_LENGTH
        FindData.dwFileAttributes = %FILE_ATTRIBUTE_NORMAL
        f = CurrentDir + "\*.*"
        hDir = FindFirstFile(f, FindData)
        If hDir = %INVALID_HANDLE_VALUE Then
           Exit For
        Else
           bytes = bytes + FindData.nFileSizeLow
           sTmp = Left$(FindData.cFilename,12) + Format$(FindData.nFileSizeLow,"###,###,###") + " " + FileDateTime(FindData) + " " + Trim$(Str$(bytes))
           If Len(St) Then St = sTmp + $CRLF Else Exit For
        End If
    Next
    Function = St
    End Function

    -------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Code:
    DIM A$, B$
    ThePath$ = "C:\TEMP"
    A$ = DIR$(ThePath$ + "\*.*")
    WHILE LEN(A$)
        B$ = B$ + A$ + $CRLF
        A$ = DIR$
    WEND
    MSGBOX B$

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      That works, thanks!! There is one slight problem though, how would i get the file size/date/time etc from it?

      I slightly modified it:

      Code:
      Function GetDirList(CurrentDir As String) Export As String
      Local A As String
      Local B As String
      A = Dir$(CurrentDir + "\*.*")
      While Len(A)
            B = B + A + $CRLF
            A = Dir$
      Wend
      Function = "Contents of " + CurrentDir + $CLRF + B
      End Function
      
      
      But this is working, to the ".." portion of the directory, stops after that...but I can get the file attributes from it...
      That first post was, um, overkill and didn't work, this seems to be more refined:
      
      
      '==============================================================================
      Function GetDirList(CurrentDir As String) Export As String
      Local hDir     As Long
      Local FindData As WIN32_FIND_DATA
      Local f        As String
      Local bytes    As Long
      Local x        As Long
      Local sTmp     As String
      Local St       As String
      Local l_FileSpec As String
      
      l_FileSpec = "*.*"
      
      %DIR_LENGTH    = 5 'Max files listed for DEBUG purposes
      
      FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
      hDir = FindFirstFile(ByVal StrPtr(CurrentDir), FindData)
      
      If hDir = %INVALID_HANDLE_VALUE Then 'Directory did not exist
          Exit Function
      Else
          FindData.dwFileAttributes = %FILE_ATTRIBUTE_NORMAL Or %FILE_ATTRIBUTE_ARCHIVE Or %FILE_ATTRIBUTE_READONLY
          For x = 1 To %DIR_LENGTH
               hDir = FindFirstFile(ByVal StrPtr(l_FileSpec), FindData)
               If FindNextFile(hDir, FindData) <> %INVALID_HANDLE_VALUE Then
                   sTmp = sTmp + Left$(FindData.cFilename,12) + " " + Format$(FindData.nFileSizeLow,"###,###,###") + " " + FileDateTime(FindData) + $CRLF
               End If
          Next
      End If
      FindClose hDir
      Function = sTmp
      End Function


      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        scott --
        look http://www.powerbasic.com/support/pb...ad.php?t=22615
        findnextfile
        ------------------


        [this message has been edited by semen matusovski (edited march 28, 2000).]

        Comment


        • #5
          Thanks, one lineof your code was all I needed to correct my mess, it works beautifully now!!


          For anyone interested, it needs more detail but this is good enough to get my by for now, there are variations posted here on the "FileDateTime" so I did not post that portion of the code...


          Code:
          '==============================================================================
          Function GetDirList(CurrentDir As String) Export As String
          Local hDir     As Long
          Local FindData As WIN32_FIND_DATA
          Local f        As String
          Local x        As Long
          Local sTmp     As String
          Local St       As String
          Local l_FileSpec As String
          
          l_FileSpec = CurrentDir + "\*.*"
          
          %DIR_LENGTH    = 5 'Max files listed for DEBUG purposes
          
          FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
          hDir = FindFirstFile(ByVal StrPtr(CurrentDir), FindData)
          If hDir = %INVALID_HANDLE_VALUE Then 'Directory did not exist
              Exit Function
          Else
              sTmp = "Directory of <" + FindData.cFilename + ">" + $CRLF
              FindData.dwFileAttributes = %FILE_ATTRIBUTE_NORMAL Or %FILE_ATTRIBUTE_ARCHIVE Or %FILE_ATTRIBUTE_READONLY
              hDir = FindFirstFile(ByVal StrPtr(l_FileSpec), FindData)
              Do
                   If Asc(FindData.cFilename) <> 46 Then ' . ..
                      sTmp = sTmp + Left$(FindData.cFilename,12) + " " + Format$(FindData.nFileSizeLow,"###,###,###") + " " + FileDateTime(FindData) + $CRLF
                   End If
              Loop While FindNextFile(hDir, FindData)
          
          End If
          FindClose hDir
          Function = sTmp
          End Function

          ------------------
          Scott
          mailto:[email protected][email protected]</A>
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment

          Working...
          X