Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to work with files in system/hidden folders
Message
De
09/01/2000 11:33:40
 
 
À
09/01/2000 08:30:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00314887
Message ID:
00315136
Vues:
79
>Hi Ed,
>
>I was trying to run the example below on my computer and I got a "too many variables" error. I can't seem to understand how that is happening. I have a large hard drive with a lot of files...
>

This is Dave's code; it's possible that with a folder that contains a lot of files, you could run out of string or memvar space. You might try inmcreasing MVCOUNT in the CONFIG.FPW to see if it helps. Scripting.FileSystemObject doesn't rely on the VFP name table or a VFP array to hold the list of files and folders in the current directory, since the object uses internal collections that aren't reliant on VFP's variable name and space management, and is less likely to bump its head because of this.

Dave's analysis of relative performance is pretty much on the money; the ADIR() mechanism is faster than the FSO mechanism, by a factor running from 2-16 times better for large file systems under both NT and Win98. At one time, there were problems with ADIR() not handling some files with variant long names, and there's a subtle error in Dave's assumption that files cannot start with a '.' - the . and .. sequences have special meanigs (. is relative to the current directory, .. to the parent folder of the current directory) so he filtered out some legal file names = the filtering could be changed to deal with that.

I still prefer the FSO approach; it's clearer to me what's being done, and the FSO offers more information and functionality than ADIR()-based approaches. OTOH, speed has its place, and you could improve the performance of the ADIR() further by changing the recursive approach to instead take an iterative aproach, inserting any subfolder directory and file entries at the end of the list to process, along the lines of:
ltStart = datetime()
CREATE CURSOR iterADIR (cFileName C(254), nSize N(10), dMod D, cTime C(8), ATTRIB C(8))
INSERT INTO iterADIR VALUES ('c:\',0,{},'','D')
GO TOP
LOCAL aFiles[1,5], nFiles, cBasePath, iRecNo, nCtr
*  We will use a cursor to serve as a dynamically sized list
DO WHILE ! EOF()
   *  extract the path prefix in case we need it
   IF 'D' $ iterADIR.ATTRIB  && this is a directory
      DIMENSION aFiles[1,5]
      ?? '.'
      cBasePath = ADDBS(ALLTRIM(iterADIR.cFileName))
      aFiles = NULL
      nFiles = ADIR(aFiles, cBasePath + '*.*','SHD')
      *  We may move the record pointer, so save its position
      iRecNo = RECNO()
      FOR nCtr = 1 TO nFiles
         *  The IF statment below strips periods from the filename
         *  If the filename is only made of '.', we will asume it's either
         *  the relative folder entry '.' or the parent folder '..'
         IF LEN(ALLTRIM(CHRTRAN(aFiles[nCtr,1],'.',''))) > 0
            *  It's a legal file - add it to the tail of the list
            INSERT INTO iterADIR VALUES ( cBasePath + aFiles[nCtr,1], ;
                                          aFiles[nCtr,2], ;
                                          aFiles[nCtr,3], ;
                                          aFiles[nCtr,4], ;
                                          aFiles[nCtr,5] )
         ENDIF
      ENDFOR
      GOTO iRecNo
   ENDIF
   SKIP
ENDDO
? datetime() - ltStart
>Thanks
>
>
* ADIR() method of recursively building the file list - Dave Frankenbach
>ltStart = datetime()
>
>create cursor filesADIR ( cFilename c(80), nSize n(10), dMod d )
>
>RecurseFolder( "c:\" )
>? datetime() - ltStart
>
>index on nSize tag nSize
>
>browse nowait
>
>function RecurseFolder( lcDir )
>local i,n, laFiles[1]
>
>?? "."
>n = adir( laFiles, lcDir + "*.*", "shd" )
>
>for i = 1 to n
>   if ( left( laFiles[i,1], 1 ) != '.' )
>      if ( "D" $ laFiles[i,5] )
>         RecurseFolder( lcDir + laFiles[i,1] + "\" )
>      else
>        insert into filesADIR ;
>               values( lcDir + laFiles[i,1], laFiles[i,2], laFiles[i,3] )
>      endif
>   endif
>endfor
>return
>
>
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform