又遇难题,请教?

bdx808 2009-09-11 08:12:36
在文件夹photo里面的下级目录里面有一些事先不知道文件名的图片文件,也不清楚有多少目录、多少文件,怎样取得里面的jpg文件的文件名。但是如果有010101309201.jpg、010101309299.jpg,那它们一定在photo\0101\013\092下面,010107301299.jpg一定在photo\0101\073\012下面,请问该如何取得这些文件的文件名放到wjm.dbf中,?
...全文
129 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdx808 2009-09-11
  • 打赏
  • 举报
回复
谢谢版主
十豆三 2009-09-11
  • 打赏
  • 举报
回复
如果只需查找 JPG 文件,将

nFoundCount = FindFiles("C:\photo","*.*", @aFiles)

改为

nFoundCount = FindFiles("C:\photo","*.jpg", @aFiles)
十豆三 2009-09-11
  • 打赏
  • 举报
回复
作者:Foxer
今天赢一个网友的要求,做一个能够支持通配符的文件查找程序,希望对大家能有帮助。
这个程序有两个方面值得看:
1.这是一个递归程序,递归程序一般不大好写,容易陷入死循环或循环不完整
2.可以学习一下如何用数组返回函数的值。另外能学习一点儿ADIR、ADDBS这类目录函数的使用方法

我以前在这里也发过一个类似的程序,但是那个是找某一个文件的,这个程序是在那个程序的基础上改的,也算是我的一个进步。
现在转向C#,很少做VFP程序了,算是给大家的一个小礼物!

Declare aFiles[1]
nFoundCount = FindFiles("C:\photo","*.*", @aFiles)
Clear
?"找到",nFoundCount,"个文件"
Display Memory Like aFiles

Return


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
bdx808 2009-09-11
  • 打赏
  • 举报
回复
比如有很多010101309201、010101309299、....990109309501(photo\9901\093\095)...等等,
bdx808 2009-09-11
  • 打赏
  • 举报
回复
谢谢三位版主,单独一个文件夹,我会用adir(),但一层一层或递归,我就不会了,请说详细些好吗?
ACMAIN_CHM 2009-09-11
  • 打赏
  • 举报
回复
[Quote= #1 apple_8180(十豆三) ]一层一层 Adir()[/Quote]

逐层检查下去了,可以使用递归函数。

还有一个方法,就是调用WINDOWS系统命令
cd c:\temp\xx
dir *.jbp /s >ff.txt

然后将ff.txt 导入。
WWWWA 2009-09-11
  • 打赏
  • 举报
回复
要用到递归调用,用FSO试试
十豆三 2009-09-11
  • 打赏
  • 举报
回复
一层一层 Adir()
bdx808 2009-09-11
  • 打赏
  • 举报
回复
apple_8180 (十豆三) 版主:能说说具体怎么用吗?谢谢啦。

2,727

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧