Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample program using the new _Files$ function
#1
Well about time! I have been waiting for a function similar to the one in BC7 called Dir$() for years! Big Grin 

This sample program searches for files with *,?,^ matching. Also recurses directories and subdirectories and their files.

Can also write output to a file and stores directory and filename arrays.

Also compatible with Win/Linux/OSX platforms.

Erik.

@a740g: Thanks for the time and effort writing a _Files$ function.

  v2.0a:
    Adds dirspec match and restart.
    Adds shellsort for dirs and files.
  v2.1a:
    Adds statusline and ctrl-break trap.
    Adds filename search to titlebar.
  v2.2a:
    Adds Case-Sensitive selection.
  v3.0a:
    Fixes print position output.
    Fixes exit loop in prompt output file.

Now 656 lines.

Things I like about _files$ is the improvement over dir$ when matching directories appended with slash and lan capability when specified as \\server\share\

[Image: filedir.jpg]

A simple breakdown of the Files$ function:

Code: (Select All)
DefLng A-Z
Rem $Dynamic

Dim Shared Directories(1) As String
Dim Shared Filenames(1) As String
Dim Shared MaxDirs As Long
Dim Shared MaxFiles As Long

Dim Directory As String
_ScreenMove _Middle
Color 15
Print "Enter dirspec";: Input Directory
If Directory = "" Then Directory = _CWD$
If _DirExists(Directory) Then
   If Right$(Directory, 1) <> "\" Then Directory = Directory + "\"
   PrintDirectory Directory
End If
Print "Dirs"; MaxDirs; "Files"; MaxFiles
Print "Dirlist:"
Count = 0
For L = 1 To MaxDirs
   Color 15
   Print Directories(L)
   Count = Count + 1
   If Count >= 24 Then
      Color 14
      Print "-more-";
      Do
         _Limit 50
         X$ = InKey$
         If LCase$(X$) = "y" Then Print: Count = 0: Exit Do
         If LCase$(X$) = "n" Then Print: Count = 0: Exit For
      Loop
   End If
Next
If Count Then
   Color 14
   Print "-more-";
   Do
      _Limit 50
      If Len(InKey$) Then Print: Exit Do
   Loop
End If
Color 15
Count = 0
Print "Filelist:"
For L = 1 To MaxFiles
   Color 15
   Print Filenames(L)
   Count = Count + 1
   If Count >= 24 Then
      Color 14
      Print "-more-";
      Do
         _Limit 50
         X$ = InKey$
         If LCase$(X$) = "y" Then Print: Count = 0: Exit Do
         If LCase$(X$) = "n" Then Print: Count = 0: Exit For
      Loop
   End If
Next
If Count Then
   Color 14
   Print "-more-";
   Do
      _Limit 50
      If Len(InKey$) Then Print: Exit Do
   Loop
End If
Color 7
End

Sub PrintDirectory (Directory As String)
   Dim I As _Unsigned Long
   Dim N As _Unsigned Long
   Dim VarX As String
   Dim Entry(0 To 0) As String
   Dim E As String
   ' start search
   E = _Files$(Directory)
   Do
      Entry(N) = E
      N = N + 1
      If N > UBound(Entry) Then
         ReDim _Preserve Entry(0 To N) As String
      End If
      ' continue search
      E = _Files$
   Loop While Len(E) > 0
   VarX$ = Directory
   GoSub StoreFile
   While I < N
      If Entry(I) <> ".\" And Entry(I) <> "..\" Then
         If Right$(Entry(I), 1) = "\" Then
            PrintDirectory Directory + Entry(I)
         Else
            VarX$ = Directory + Entry(I)
            GoSub StoreFile
         End If
      End If
      I = I + 1
   Wend
   Exit Sub
   StoreFile:
   If Right$(VarX$, 1) = "\" Then
      MaxDirs = MaxDirs + 1
      ReDim _Preserve Directories(MaxDirs) As String
      Directories(MaxDirs) = VarX$
   Else
      MaxFiles = MaxFiles + 1
      ReDim _Preserve Filenames(MaxFiles) As String
      Filenames(MaxFiles) = VarX$
   End If
   Return
End Sub


Attached Files
.zip   FILEDIR3.ZIP (Size: 4.85 KB / Downloads: 13)
Reply


Messages In This Thread
Sample program using the new _Files$ function - by eoredson - 01-20-2024, 04:29 AM



Users browsing this thread: 1 Guest(s)