文件、文件夹操作(I)
生活随笔
收集整理的這篇文章主要介紹了
文件、文件夹操作(I)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
遍歷一個目錄下的所有文件
首先我們獲取用戶文檔目錄路徑
1 let manager = FileManager.default 2 let urlForDocument = manager.urls(for: .documentDirectory, in:.userDomainMask) 3 let url = urlForDocument[0] as URL 4 print("---------->\(url)") View Code打印結果:
---------->file:///Users/huanggang/Library/Developer/CoreSimulator/Devices/7B9AE7A4-4838-495B-964D-560DF760F7E1/data/Containers/Data/Application/70D8DA8D-4FEF-4715-B82E-0F40C1BC1B78/Documents/
?
深度遍歷,會遞歸遍歷子文件夾
1 let enumeratorAtPath = manager.enumerator(atPath: url.path) 2 enumeratorAtPath?.skipDescendants() //跳過遞歸到最近獲得的子目錄 3 print("enumeratorAtPath: \(enumeratorAtPath?.allObjects)") View Code打印結果:
enumeratorAtPath: Optional([])
?
參考:文件夾操作
?
轉載于:https://www.cnblogs.com/EchoHG/p/9064880.html
總結
以上是生活随笔為你收集整理的文件、文件夹操作(I)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 文件指针及文件覆盖
- 下一篇: Elizabeth Taylor【伊丽莎