当前位置: 代码迷 >> VFP >> 论坛apple_8180 关于应用adir()历遍文件夹得到指定类型的文件,数量过大时,会出错
  详细解决方案

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

热度:3566   发布时间:2013-02-26 00:00:00.0
论坛apple_8180 关于使用adir()历遍文件夹得到指定类型的文件,数量过大时,会出错
原贴在这里:[url=http://topic.csdn.net/u/20090104/17/44a67045-00c2-4a9a-ab98-e7f388fa803d][/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]   =   ".. "