I'm having same trouble. I can't scan the contents of folder at QNAP NAS connected with SMB.
import SwiftUI
struct ContentView: View {
@State private var showPicker = false
@State private var files: [URL] = []
var body: some View {
VStack {
Button("Open Folder...") { showPicker.toggle() }
.font(.largeTitle)
.padding(.bottom)
if files.isEmpty {
Text("EMPTY")
.font(.largeTitle)
.foregroundColor(.secondary)
.frame(maxHeight: .infinity)
} else {
ScrollView {
VStack {
ForEach(files, id: \.self) { url in
Text(url.lastPathComponent)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.padding(.leading)
}
.frame(maxHeight: .infinity, alignment: .topLeading)
}
}
.padding()
.fileImporter(isPresented: $showPicker, allowedContentTypes: [.folder]) { result in
switch result {
case .success(let url):
scanFolder(url)
case .failure(let error):
print("[ERROR] \(error)")
}
}
}
private func scanFolder(_ folderURL: URL) {
let secure = folderURL.startAccessingSecurityScopedResource()
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: folderURL.path)
files = contents.map { folderURL.appending(path: $0) }
} catch {
print("[ERROR] contentsOfDirectory \(error)")
}
if secure {
folderURL.stopAccessingSecurityScopedResource()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Also, Apple's Folder.app can't copy the folder in NAS to iCloud Drive. When I copy the folder in NAS and paste it in iCloud/On device, the empty folder is created.
Of corse I have permission for accessing NAS.
I can copy files from NAS to iCloud.
Post
Replies
Boosts
Views
Activity
Same here!