Moving a file from the project folder to the data directory at runtime
Hello,
My game has a SQLite database stored as a .sqdb file at Application.persistentDataPath. I'd like to have default content in the database. I was thinking I could keep a .sqdb file in the project folder and copy it over to the data directory the first time the user opens the app. I'm not sure how to accomplish that though.
Comment
Answer by commodore · Dec 14, 2015 at 04:35 PM
I figured it out. Here it is if anyone's curious. Make sure you're using System.IO.
public void CopyFileIfNonexistent (string fileName) {
string dataPath = Application.persistentDataPath + "/" + fileName;
string assetPath = "Assets/Mobile/Resources/" + fileName;
if(!File.Exists(dataPath)) {
// File doesn't exist, move it from assets folder to data directory
File.Copy(assetPath, dataPath);
}
}