silktest 通过递归实现文件搜索的…

本文介绍了一种使用SilkTest进行文件搜索的方法,通过递归实现目录及其子目录下匹配指定模式的所有文件路径检索。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

silktest 通过递归实现文件搜索的方法,个人觉得很有用:
  [-] list of STRING  glSYS_SearchFile(STRING sDir, STRING sPattern optional, boolean bContainsSubDir optional)
            [ ] // find all files whose file name matched sPattern under sDir, ignore case
            [ ] // return the expected file path
            [-] if (sPattern == null)
                [ ] sPattern = "*"
            [-] if (bContainsSubDir == null)
                [ ] bContainsSubDir = false
            [-] if (!SYS_DirExists(sDir))
                [ ] RaiseError(-3,"Directory '{sDir}' is not exists!")
            [ ] sDir = Trim(sDir)
            [ ] list of STRING lsResult
            [ ] list of FILEINFO lfContents = SYS_GetDirContents(sDir)
            [ ] FILEINFO fItem
            [-] for each fItem in lfContents
                [-] if (fItem.bIsDir)  // is a directory
                    [-] if (bContainsSubDir)  // whether to clear the sub directory
                        [ ] ListMerge(lsResult,(glSYS_SearchFile(sDir+"\"+fItem.sName,sPattern,true)))
                [-] else
                    [-] if (MatchStr(lower(sPattern),lower(fItem.sName)))
                        [ ] ListAppend(lsResult,sDir+"\"+fItem.sName)
            [ ] return lsResult

调用,例如:
List of String liResults=glSYS_SearchFile("F:\","test.txt",True)
Print(
liResults)
执行看看效果^_^

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值