DolphinDB函数files
只能列出当前目录下的所有文件,文件名不是完整路径.如何像Linux find
命令一样列出目录中所有扩展名为.gz的文件?
[xjqian@k8s-2 ~]$ find ./ -name "*.gz"
./cmake-3.12.3.tar.gz
./mongoose/test/data/hello.txt.gz
DolphinDB函数files
只能列出当前目录下的所有文件,文件名不是完整路径.如何像Linux find
命令一样列出目录中所有扩展名为.gz的文件?
[xjqian@k8s-2 ~]$ find ./ -name "*.gz"
./cmake-3.12.3.tar.gz
./mongoose/test/data/hello.txt.gz
您可以定义如下函数:
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