Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func copyfileToDocumentDirectory() {
- let fileName = "Test01"
- let fileType = "jpg"
- let copyfileName = fileName
- let copyfileType = fileType
- guard let bundlePath = Bundle.main.path(forResource: fileName, ofType: fileType),
- let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
- let fullDocumentPath = NSURL(fileURLWithPath: documentPath).appendingPathComponent("\(copyfileName).\(copyfileType)")
- else { return }
- let fileManager = FileManager.default
- let fullDocumentPathString = fullDocumentPath.path
- if fileManager.fileExists(atPath: fullDocumentPathString) {
- print("The file exists and can not be copied.")
- } else {
- do {
- try fileManager.copyItem(atPath: bundlePath, toPath: fullDocumentPathString)
- print("Copied")
- } catch {
- print(error)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement