I have folders with files inside them in my main bundle, and I want to copy/cut them to the Documents Directory at first launch of the application to access them from there. I've seen examples but they're all in Obj-C and I'm using Swift 3. How can I do this?
Swift 3 - Copy Folder w/ contents from Main Bundle to Documents Directory
4k views Asked by SergeH At
2
There are 2 answers
0
Tomm P
On
There is a built in FileManager function to do this.
"If the item at srcURL is a directory, this method copies the directory and all of its contents, including any hidden files."
do {
let docsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let sourceURL = Bundle.main.resourceURL!.appendingPathComponent("sourceDir").absoluteURL
let destinationURL = docsURL.appendingPathComponent("destDir").absoluteURL
try FileManager.default.copyItem(at: sourceURL, to: destinationURL)
} catch {
print("\nError\n")
}
Related Questions in IOS
- URLSession requesting JSON array from server not working
- Incorrect display of LinearGradientBrush in IOS
- Module not found when building flutter app for IOS
- How to share metadata of an audio url file to a WhatsApp conversation with friends
- Occasional crash at NSURLSessionDataTask dataTaskWithRequest:completionHandler:
- Expo Deep linking on iOS is not working (because of Google sign-in?)
- On iOS, the keyboard does not offer a 6-character SMS code
- Hi, there is an error happened when I build my flutter app, after I'm installing firebase packages occurs that error
- The copy/paste functionalities don't work only on iOS in the Flutter app
- Hide LiveActivityIntent Button from Shortcuts App
- While Running Github Actions Pipeline: No Signing Certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID
- Actionable notification api call not working in background
- Accessibility : Full keyboard access with scroll view in swiftui
- There is a problem with the request entity - You are not allowed to create 'iOS' profile with App ID 'XXXX'
- I am getting "binding has not yet been initialized" error when trying to connect firebase with flutter
Related Questions in SWIFT3
- Why is the Navigation Title and Picker View is scrolling without it being inside a Scroll View?
- How to trigger onAppear when returning from fullScreenCover
- SwiftUI - WebView
- Error while trying to scan a document using a scanner device in macOS in the Swift/SwiftUI App
- In SwiftUI on MacOS Detect Clicks and Doubleclicks in List
- Maintaining Vertical Offset from Touchpoint after View Rotation in iOS
- fullScreenCover dissmissed after swipe of tabView | SwiftUI | iOS
- Error: extensions must not contain stored properties in swift
- Error dismissing image picking and cropping views when using TOCropViewController to pick images in SwiftUI
- How to use extern Structure in a View correctly?
- Navigation Bar Not Showing Up SwiftUI
- Decoding JSON with SWIFT CodingKeys Error
- Swift GestureRecognizer
- swift drag and drop functionality is not working properly
- Text modifiers in Data
Related Questions in MAINBUNDLE
- Remove a js array from the Next js main bundle
- Resources with identical names in the main bundle
- NSURL from image works fine but not with certificate file
- Add new language string file dynamically for localisation in iOS
- Json file is null when prints in bundle resource ios ionic objective c
- Swift 3 - Copy Folder w/ contents from Main Bundle to Documents Directory
- Get Nil when retrieving file path form Main Bundle when file is in Copy Bundle
- Save an image from photo library to Main Bundle in app Xcode
- Locating custom files in iOS app
- NSBundle.mainBundle() returns nil
- How do I access 'lost' media assets in iOS mainBundle?
- Scanning the contents of a directory in an app's main bundle
- Referencing directories within an Xcode project for an iOS app
- How mainBundle() return on object in swift or objective-c?
- Are all the resources of an App Bundle copied to memory (RAM) when an iOS App Launches?
Related Questions in DOCUMENTSDIRECTORY
- Access Documents directory contents in files app in ios 15
- Saving data in Documents Directory in iOS, SwiftUI
- Deleting a folder from the documentsDirectory with Swift
- Updating a bool variable after saving image to documents directory doesn’t work as expected in Swift
- access documents directory on physical device
- Read and write data from & to text file in Documents Directory incrementally with Swift
- How to read string from Text which saved in Documents Directory with Swift?
- How to add or import multiple items to a file which saved in Documents Directory with Swift?
- Swift 3 - Copy Folder w/ contents from Main Bundle to Documents Directory
- UWP save file in Documents and Pictures Library
- Error: "unable to open database file" & "Too many open files"
- Binary to pdf convert without store in documentsDirectory in obj c
- How to access images stored in Documents Directory in ios8
- NSData made from gif file reduced to less than 10kb when sending via email
- Path to file is modified by another view controller
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I managed to do it using 2 functions: