2017-09-06 69 views
0

如何從文檔/收件箱/目錄中選擇zip文件。也給選定的文件參考變量。如何從文檔/收件箱/在Swift 3中選擇.zip文件

let filemanager:FileManager = FileManager() 
    let files = filemanager.enumerator(atPath: NSHomeDirectory()) 
    while let file = files?.nextObject() { 
     print("Files::",file) 
} 

o/p: 
Files:: Documents/Inbox 
Files:: Documents/Inbox/abc.zip 
Files:: Documents/Inbox/pqrs.zip 
Files:: Documents/Inbox/xyz.zip 
Files:: Library 
Files:: Library/Caches 
Files:: Library/Caches/Snapshots 
Files:: Library/Preferences 

我需要從該列表中選擇zip文件。

+0

您必須應用謂詞並設置獲取.zip文件的正確路徑。 –

回答

0

迅速3

let filemanager:FileManager = FileManager() 
    let files = filemanager.enumerator(atPath: NSHomeDirectory()) 
    while let file = files?.nextObject() { 

     //print("Files::",file) 

     if (String(describing: file).characters.count >= 4){ 

      let fileName = file as! String 

      if fileName.substring(from:fileName.index(fileName.endIndex, offsetBy: -4)) == ".zip"{ 

       print((file as! NSString).lastPathComponent) 
       self.arrayZipfile.append((file as! NSString).lastPathComponent) 
      } 
     } 
    } 

選擇arrayZipFile索引。