ftp新增获取过滤后文件名或目录名列表的方法

This commit is contained in:
kirito 2023-12-20 10:44:48 +08:00
parent 494c70b9e6
commit 9ec433027e

View File

@ -12,6 +12,7 @@
package org.dromara.hutool.extra.ftp;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.io.IORuntimeException;
@ -350,6 +351,18 @@ public class Ftp extends AbstractFtp {
return ArrayUtil.map(lsFiles(path), FTPFile::getName);
}
/**
* 遍历某个目录下所有文件和目录不会递归遍历<br>
* 此方法自动过滤"."".."两种目录
*
* @param path 目录
* @param predicate 过滤器null表示不过滤默认去掉"."".."两种目录
* @return 文件名或目录名列表
*/
public List<String> ls(final String path, final Predicate<FTPFile> predicate) {
return CollUtil.map(lsFiles(path, predicate), FTPFile::getName);
}
/**
* 遍历某个目录下所有文件和目录不会递归遍历<br>
* 此方法自动过滤"."".."两种目录