files 命令如何递归地检索目录下的文件?

https://www.dolphindb.cn/cn/help/FunctionsandCommands/FunctionReferences/f/files.html

仅能列出当前目录下的文件,且 filename 不是完整路径 

如何像 Linux 的 find 命令一样?

请先 登录 后评论

1 个回答

alex

可以写个自定义函数:

def findR(path, pattern=NULL){
	t = files(path)
	if (isValid(pattern)){
		t = files(path, pattern)
	}
	res = select * from t where !isDir
	update res set res.filename = path +"/" + res.filename
	for (f in select * from files(path) where !!isDir){
		try {
			subRes =  findR(path+"/"+f.filename, pattern)
			res.append!(subRes)
		} catch(ex){
			print("ex:"+path+"/"+f.filename+ string(f.isDir))
		}
	}
	return res
}

用法举例:

findR("c:/tmp", pattern="%.log")

输出:

filename	        isDir	fileSize	lastAccessed	lastModified
c:/tmp/controller.log	false	543,619,626	2022.05.14T09:09:52.405	2022.05.14T06:04:22.000
c:/tmp/P1-node1.log	false	729,729,122	2022.05.14T09:10:05.156	2022.05.14T05:44:13.000
c:/tmp/bd/Output.log	false	44,088	        2022.04.03T12:30:56.523	2022.04.03T12:30:56.523
请先 登录 后评论