[英]smbj: How can I get subdirectories only?
I use https://github.com/hierynomus/smbj for samba access. 我使用https://github.com/hierynomus/smbj进行samba访问。 I want get only the subfolders of my target directory.
我只想获取目标目录的子文件夹。 Whith following code I get "..", "."
在下面的代码中,我得到“ ..”,“。” and all the files - is there an elegant way to get subdirectories only?
和所有文件-是否有一种优雅的方法仅获取子目录?
SmbConfig config = SmbConfig.builder().withMultiProtocolNegotiate(true).build();
smbClient = new SMBClient(config);
Connection connection = smbClient.connect(smbServerName);
AuthenticationContext ac = new AuthenticationContext(smbUser, smbPassword.toCharArray(), smbDomain);
Session session = connection.authenticate(ac);
share = (DiskShare) session.connectShare(smbShareName);
List<FileIdBothDirectoryInformation> subs = share.list("mydirWhichSubDirsIwant");
You need to filter out the results from the returned list. 您需要从返回的列表中过滤出结果。 If you only want the subdirectories you can get them as follows:
如果只需要子目录,则可以按以下方式获取它们:
List<String> subDirectories = new ArrayList<>();
for (FileIdBothDirectoryInformation sub: subs) {
String filename = sub.getFileName();
if (".".equals(filename) || "..".equals(filename)) {
continue;
}
if (EnumWithValue.EnumUtils.isSet(sub.getFileAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY)) {
subDirectories.add(filename);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.