Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let fileManager = FileManager.default
- //獲得App沙盒根路徑
- let filePath:String = NSHomeDirectory()
- print(filePath)
- // 獲得Docuents路徑(NSSearchPathForDirectoriesInDomains 返回絕對路徑)(要查找的目錄, 是否是用户主目錄, YES/NO 是否是否獲取全路徑))
- let filePPath2 = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
- print(filePPath2)
- // 獲取Document相對路徑
- let documentsDirectory = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Document")
- print(documentsDirectory)
- // 獲取Library路徑
- let library = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)
- print(library)
- // 獲取相對於Home的Library路徑
- let libraryByHome = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Library")
- // 獲取Cache路徑
- let cachePath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
- print("Cache路徑\(cachePath)")
- // 獲取相對於Home的Cache
- let letcacheHomePath = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Cache")
- print("Cache路徑\(letcacheHomePath)")
- // 獲取Tmp路徑
- var tmpPath = NSTemporaryDirectory()
- print(tmpPath)
- // 相對於Home的tmp
- let tmpByHome = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("tmp")
- print(tmpByHome)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement