我使用https://github.com/hierynomus/smbj进行samba访问。 我只想获取目标目录的子文件夹。 在下面的代码中,我得到“ ..”,“。”和所有文件-是否有一种优雅的方法仅获取子目录?
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import {LoginService} from './login.service';
import {TokenService} from '../data/token.service';
import {Router} from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
providers: [LoginService]
})
export class LoginComponent implements OnInit {
constructor(private loginService: LoginService, private tokenService: TokenService, private router: Router) { }
ngOnInit() {
if (this.tokenService.getToken() !== '') {
console.log(this.tokenService.tk);
this.router.navigate(['/admin']);
}
}
onSubmit(form: NgForm) {
this.loginService.login(form.value.email, form.value.password);
}
}
答案 0 :(得分:1)
您需要从返回的列表中过滤出结果。如果只需要子目录,则可以按以下方式获取它们:
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);
}
}