FirstFile$
File$ = FirstFile$(Folder$)
 
Parameters:

    Folder$ = The name of the folder you wish to read the file / folder names from
Returns:

    File$ = The name of the first file or folder name in this folder
 

      The FirstFile$ function will return the first file or folder name linked in folder. The function will return a null (empty) string if there were no more files or folders in the requested folder. After reading the first file, you need to use "" to read any following files.



FACTS:


      * FirstFile$ sets the internal FirstFile$() path, which NextFile$() will also use.

      * Files listed with the FirstFile$,NextFile$ functions, will be listed in the order windows has internally linked them. This order will normally appear random. If you want them to be displayed in (alphabetic) order, use the ReadDir functions.




Example #1:


      This example lists the files and folders on your C: drive

  
  
; Get the first file from the c drive
  File$=FirstFile$("c:")
  
; While File$ string is not empty,
;  run the code inside the while loop
  While File$<>""
     
   ; Display the File$ or folder name
     Print file$
     
   ; Get the next file from this folder
     File$=NextFile$()
     
   ; Jump back to the while statement to keep looping
  EndWhile
  
; Display the screen and wait for key press
  Sync
  WaitKey
  




Example #2:


      This example reads the files + folders in an array to a string array.

  
  
  
  // declare array to hold the files
  Dim Files$(1024)
  
  // declare the location /drive to search
  Path$="C:\"
  
  // Call function to read the files/folders into our array
  Count=ReadFilesToArray(Path$,Files$())
  
  
  // print the list to the screen
  For lp=0 To Count-1
     Print Files$(lp)
  Next
  
  // show the screen to the user and wait for key press
  Sync
  WaitKey
  End
  
  
  
Function ReadFilesToArray(Path$,FileArray$())
  
; check if this location exists ??
  If FolderExist(Path$)
     
   ; get the size of this array ?
     Local FileLIstMax=GetArrayElements(FileArray$())
     
   ; get the first file in this location
     Local file$=FirstFile$(path$)
     While Len(file$)
        
      ; check if our count if bugger than our arrays size
      ; if so, we resize the array with some padding
        If Count=>FileLIstMax
         ; Make the array twice the size so we don't need
         ; to keep resizing it.
           FileLIstMax=(Count*2)+256
           ReDim FileArray$(FileLIstMax)
        EndIf
        
      ; store this file.  This file might be a folder name also
        FileArray$(Count) =File$
        
      ; increaes the number of files we've found
        Count++
        
      ; grab the next file
        File$=NextFile$()
     EndWhile
     
  EndIf
  
EndFunction Count
  
  







 
Related Info: FileSize | FileType | NextFile$ | OpenFile | ReadDir :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com