Guest User

Untitled

a guest
Oct 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. let fileManager = FileManager.default
  2. //獲得App沙盒根路徑
  3. let filePath:String = NSHomeDirectory()
  4. print(filePath)
  5. // 獲得Docuents路徑(NSSearchPathForDirectoriesInDomains 返回絕對路徑)(要查找的目錄, 是否是用户主目錄, YES/NO 是否是否獲取全路徑))
  6. let filePPath2 = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
  7. print(filePPath2)
  8.  
  9. // 獲取Document相對路徑
  10. let documentsDirectory = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Document")
  11. print(documentsDirectory)
  12.  
  13. // 獲取Library路徑
  14. let library = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
  15. print(library)
  16.  
  17. // 獲取相對於Home的Library路徑
  18. let libraryByHome = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Library")
  19.  
  20. // 獲取Cache路徑
  21. let cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
  22. print("Cache路徑\(cachePath)")
  23.  
  24. // 獲取相對於Home的Cache
  25. let letcacheHomePath = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Cache")
  26. print("Cache路徑\(letcacheHomePath)")
  27.  
  28. // 獲取Tmp路徑
  29. var tmpPath = NSTemporaryDirectory()
  30. print(tmpPath)
  31. // 相對於Home的tmp
  32. let tmpByHome = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("tmp")
  33.  
  34. print(tmpByHome)
Add Comment
Please, Sign In to add comment