首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

论坛apple_8180 关于应用adir()历遍文件夹得到指定类型的文件,数量过大时,会出错

2012-09-02 
论坛apple_8180 关于使用adir()历遍文件夹得到指定类型的文件,数量过大时,会出错原贴在这里:[urlhttp://t

论坛apple_8180 关于使用adir()历遍文件夹得到指定类型的文件,数量过大时,会出错
原贴在这里:[url=http://topic.csdn.net/u/20090104/17/44a67045-00c2-4a9a-ab98-e7f388fa803d.html][/url]
我小改了一下:
昨天和今天测试中,当一个文件夹下面的jpg文件超过13600左右就会出错,我用的是VFP7
1、不知道有没有办法改为无限大,或者大于十万条。
2、这程序能否同时搜索多个文件类型,如:*.jpg,*.bmp,*.mpg....
3、能否把这程序改为只搜索指定的文件夹,不包括子文件夹,或者做一个选项,只扫描指定文件夹,而不包括子文件夹或包括子文件夹都扫描

Create   table   mylsdbf   (wjmc   c(120),path   c(100),filename   c(50))&&创建一个表,把扫描到的文件保存到这个表里面
  Declare   aFiles[1]  
  For   lnI=67   To   90&&从C盘循环至Z盘  
  If   Drivetype(Chr(lnI))> 2&&   or   Drivetype(Chr(lnI))=6   &&硬盘  
  nFoundCount   =   FindFiles(Chr(lnI)+ ":\ ", "*.jpg ",   @aFiles)   &&通过程序查找
  For   lnJ=1   To   nFoundCount   &&在指定目录下找到的文件数量
  inse   into   mylsdbf(wjmc,filename,path)   value   (aFiles(1,lnJ), " ", " "))))))&&在表里增加一行记录
  Endfor  
  Endif  
  Endfor  

  *--以下为   Foxer   大侠提供的“支持通配符的文件匹配查找的程序”,在此表示感谢。  
  Function   FindFiles  
  Lparameters   cPath,   cFindFile,   aFindFiles  
  External   Array   aFindFiles  
  If   Empty(cPath)   Or   Empty(cFindFile)  
  Return   " "  
  Endif  
  cFindFile   =   Alltrim(Upper(cFindFile))  
  If   Diskspace(cPath)     <   0   &&   不存在  
  Return   " "  
  Endif  
  Declare   aFindFiles[1]  
  nFoundCount   =   FileLocate(cPath,   cFindFile,   @aFindFiles)  
  Return   nFoundCount  
  Endfunc  
  Function   FileLocate  
  Lparameters   cPath,   cFindFile,   aFindFiles  
  Private   All  
  External   Array   aFindFiles  
   
  nFoundCount   =   0  
  Local   Array   aFiles[1]  
  Local   Array   aMatchFiles[1]  
  nFiles   =   Adir(aFiles,   Addbs(cPath)   +   "*.* ", "DRASH ",   1)  
  nMatchFiles   =   Adir(aMatchFiles,   Addbs(cPath)   +   cFindFile, "DRASH ",   1)  
   
  If   nMatchFiles>   0  
  For   i   =   1   To   nMatchFiles  
  If   Not   (aMatchFiles[i,1]   =   ". "   Or   aMatchFiles[i,1]   =   ".. ")  
  If   "D "   $   aMatchFiles[i,5]   &&   目录  
  Loop  
  Endif  
  nFoundCount   =   nFoundCount   +   1  
  Declare   aFindFiles[nFoundCount]  
  aFindFiles[nFoundCount]   =   Addbs(cPath)   +   aMatchFiles[i,1]  
  Endif  
  Endfor  
  Endif  
   
  If   nFiles   >   0  
  For   i   =   1   To   nFiles  
  If   aFiles[i,1]   =   ". "   Or   aFiles[i,1]   =   ".. "  


  Loop  
  Endif  
  If   "D "   $aFiles[i,5]   &&   目录  
  Local   Array   aSubFoundFiles[1]  
  nSubFoundCount   =   FileLocate(Addbs(cPath)   +   aFiles[i,1],   cFindFile,   @aSubFoundFiles)  
  If   nSubFoundCount   >   0   &&   找到了  
  For   j   =   1   To   nSubFoundCount  
  nFoundCount   =   nFoundCount   +   1  
  Declare   aFindFiles[nFoundCount]  
  aFindFiles[nFoundCount]   =   aSubFoundFiles[j]  
  Endfor  
  Endif  
  Endif  
  Endfor  
  Endif  
   
  Return   nFoundCount  
  Endfunc


[解决办法]
VFP自带的Filer.dll

SQL code
ClearoMyFiler=Createobject('Filer.FileUtil')oMyFiler.SearchPath='C:\要搜索的目录'oMyFiler.SubFolder=0                    && 0不搜索子文件夹,1搜索指定的文件夹及其所有的子文件夹oMyFiler.FileExpression='*.exe;*.wav;*.txt'    && 搜索 exe 和 wav 文件oMyFiler.Find(0)For nFileCount=1 To oMyFiler.Files.Count    ? oMyFiler.Files.Item(nFileCount).Path    && 显示文件的完整路径    ?? oMyFiler.Files.Item(nFileCount).Name    && 显示文件的名称Endfor 

热点排行