Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FileSystemObject
Message
De
04/03/2003 08:44:56
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/03/2003 07:54:43
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00760809
Message ID:
00760825
Vues:
13
>I need to travers the file system to count the number of tiff files in the lowest folder
>i have prg which works as long as the limit of an array is not reached
>If there are more then 12000+- it breaks.
>
>Can I use the FSO instead of adir

Peter,
You could use FSO. ie:
lcStartDir = getdir()
start = seconds()
Gettree(lcStartDir,.t.)
? seconds()-start
browse

function Gettree
lparameters tcDirectory, tlFiles
create cursor crsFiles ;
  (FolderId i, Filename m, FileSize i, Created t, Modified t, Accessed t)
create cursor crsFolders (Folder m, FolderId i)

oFS = createobject('Scripting.FileSystemObject')
oFolder = oFS.GetFolder(tcDirectory)
insert into crsFolders ;
  (Folder , FolderId ) ;
  values ;
  (oFolder.path, reccount('crsFolders')+1)
if tlFiles
  GetFiles(oFolder, reccount('crsFolders'))
endif

tcDirectory = iif(oFolder.IsRootFolder(), substr(tcDirectory,1,len(tcDirectory)-1), tcDirectory)
=_SubFolders(oFolder, tcDirectory, tcDirectory,tlFiles)
select crsFiles
index on FolderId tag FolderId
local array arrFolderSize[1], arrFileNameSize[1]
local lnFolderSize, lnFileNameSize

select max(len(Folder)) from crsFolders into array arrFolderSize
select max(len(Filename)) from crsFiles into array arrFileNameSize
lnFolderSize = min(254,arrFolderSize)
lnFileNameSize = min(254, arrFileNameSize)

select padr(Folder,lnFolderSize) as 'Folder', padr(Filename,lnFileNameSize) as 'Filename', ;
  FileSize , Created , Modified , Accessed ;
  from crsFolders join crsFiles on crsFolders.FolderId = crsFiles.FolderId ;
  into cursor crsResult

function _SubFolders
lparameters toFolder, tcPath, tcStartPath, tlFiles
local loSubFolders
tcPath = tcStartPath
for each oSubFolder in toFolder.Subfolders
  if oSubFolder.name # "System Volume Information"
    insert into crsFolders ;
      (Folder , FolderId ) ;
      values ;
      (oSubFolder.path, reccount('crsFolders')+1)
    if tlFiles
      GetFiles(oSubFolder, reccount('crsFolders'))
    endif
    =_SubFolders(oSubFolder, tcPath, tcPath+"\"+ oSubFolder.name, tlFiles)
  endif
endfor

function GetFiles
lparameters toFolder, tnId
for each oFile in toFolder.files
  insert into crsFiles ;
    (FolderId, Filename, FileSize, Modified, Accessed , Created ) ;
    values ;
    (tnId, oFile.name, oFile.size, ;
    oFile.DateCreated, oFile.DateLastModified, oFile.DateLastAccessed)
endfor
However there is faster and cleaner utility that comes with foxpro - filer :)
lcSTartDir = GETDIR()
lnStart = SECONDS()
*lnFiles = GetTree(lcStartDir,'*.dbf;*.cd;*.fpt', 'myCursor', .t.)
lnFiles = GetTree(lcStartDir,'*.*', 'myCursor', .t.)
? SECONDS()-lnStart
Local array arrSizeTot[1]
Select sum(FileSize) from myCursor into array arrSizeTot
? trans(iif(_Tally>0,arrSizeTot,0))+' bytes in '+trans(lnFiles)+' files.'

Function GetTree
Lparameters tcStartDir,tcSkeleton,tcCursorName,;
  tlSubfolders,;
  tlWholeWords,tlIgnoreCase,tlSearchAnd,tcSearch1,tcSearch2,tcSearch3
Create Cursor (tcCursorName) ;
  (filepath c(50), filename c(20), ;
  FileSize i, fattr c(8), createtime T, lastacc T, lastwrite T)
Local oFiler, lnFound
oFiler = Createobject('filer.fileutil')
With oFiler
  .SearchPath = tcStartDir
  .FileExpression = tcSkeleton && Search for skeleton
  .Subfolder   = iif(tlSubfolders,1,0)  && Check subfolders
  .IgnoreCase  = iif(tlIgnoreCase,1,0)
  .WholeWords  = iif(tlWholeWords,1,0)
  .SearchAnd   = iif(tlSearchAnd,1,0)
  .SearchText1 = iif(empty(tcSearch1),"",tcSearch1)
  .SearchText2 = iif(empty(tcSearch2),"",tcSearch2)
  .SearchText3 = iif(empty(tcSearch3),"",tcSearch3)
  lnFound = .Find(0)
  For ix=1 To lnFound
    With .Files(ix)
      If !(Bittest(.Attr,4) And .Name = '.')
        Insert Into (tcCursorName) ;
          (filepath, filename, FileSize, fattr, createtime, lastacc, lastwrite)  ;
          values ;
          (.Path, .Name, .Size, Attr2Char(.Attr), ;
          Num2Time(.Datetime), Num2Time(.LastAccessTime), ;
          Num2Time(.LastWriteTime))
      Endif
    Endwith
  Endfor
Endwith
Return lnFound

Function Num2Time
Lparameters tnFloat
Return Dtot({^1899/12/30}+Int(tnFloat))+86400*(tnFloat-Int(tnFloat))

Function Attr2Char
Lparameters tnAttr
Return ;
  IIF(Bittest(tnAttr,0),'RO','RW')+;
  IIF(Bittest(tnAttr,1),'H','_')+;
  IIF(Bittest(tnAttr,2),'S','_')+;
  IIF(Bittest(tnAttr,4),'D','_')+;
  IIF(Bittest(tnAttr,5),'A','_')+;
  IIF(Bittest(tnAttr,6),'E','_')+;
  IIF(Bittest(tnAttr,7),'N','_')
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform