1Let FileManager = FileManager.default()2 3Let Urlarray =filemanager.urlsfordirectory (FileManager.SearchPathDirectory.userDirectory, Indomains: FileManager.SearchPathDomainMask.allDomainsMask)4 5 forUrlinchUrlarray {6Print ("url = \ (URL)")7 8Let Reskeys =[Urlresourcekey.namekey, Urlresourcekey.isdirectorykey]9 TenLet Reskeysstr =[URLResourceKey.nameKey.rawValue, URLResourceKey.isDirectoryKey.rawValue] One ALet Direnumerator = Filemanager.enumerator (At:url, INCLUDINGPROPERTIESFORKEYS:RESKEYSSTR, Options: [. Skipshiddenfiles,], Errorhandler:nil)! - - for CaseLet FileUrl as NsurlinchDirenumerator { theGuard Let Resvalues =Try?fileurl.resourcevalues (Forkeys:reskeys), -Let isdirectory = Resvalues[urlresourcekey.isdirectorykey] as?Bool, -Let name = Resvalues[urlresourcekey.namekey] as?String - Else { + Continue - } + A ifisdirectory { at direnumerator.skipdescendants () -Print ("dir name is: \ (name)") -}Else { -Print ("file name is: \ (name)") - } - } in -}
List files for the specified folder