let localFileManager = FileManager()
let resourceKeys = Set<URLResourceKey>([.nameKey, .pathKey, .creationDateKey, .isDirectoryKey,.totalFileSizeKey])
let directoryEnumerator = localFileManager.enumerator(at: URL(string: "/")!, includingPropertiesForKeys: Array(resourceKeys), options: .skipsHiddenFiles)!
for case let fileURL as URL in directoryEnumerator {
guard let resourceValues = try? fileURL.resourceValues(forKeys: resourceKeys),
let isDirectory = resourceValues.isDirectory,
let name = resourceValues.name,
let path = resourceValues.path,
let date = resourceValues.creationDate,
let size = resourceValues.totalFileSize
else {
continue
}
if isDirectory {
if name == "_extras" { // use this to exclude a given directory
directoryEnumerator.skipDescendants()
}
} else {
// // append elements in date order here?
// print(fileURL)
// 輸出全部文件
// print(resourceValues)
//
// fileURLs.append(fileURL) // full URLs of files
// fileNames.append(name) // file names only
// filePaths.append(path) // paths of file
// fileDates.append(date) // date and time that file was created
//
// // sort arrays by creation date here?
}
}
macOS開發(fā)之獲取Macintosh HD磁盤下全部文件
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 獲取Macintosh HD磁盤下的目錄列表: 獲取文件列表的函數(shù): 獲取文件信息的函數(shù): 獲取文件圖標(biāo)的代碼:
- ??本文介紹基于C++ 語言,遍歷文件夾中的全部文件,并從中獲取指定類型的文件的方法。 ??首先,我們來明確一下本...
- with open('test.txt','r+') as f: a = input("請輸入內(nèi)容:") ...
- def reverse_complement(seq): ntComplement = {'A':'T','T'...