Can't delete file from Streamingassets

Hello

I have an editor script, that should copy a db file to StreamingAssets folder, then open it and do stuff, then delete it.
Here is a simple test that fails with this exception:

IOException: Sharing violation on path C:/dev/Assets/StreamingAssets/tempDbFile.db
System.IO.File.Delete (System.String path)
EditorAssetBundleExtensions.FileTest () (at test.cs:467)

void FileTest(){
	//I want to copy this file...
	string oldDbFileFullPath = Application.dataPath + "/Editor/OldDb/dfile.db";
	
	//...to here
	string tempFileFullPath =  Application.dataPath + "/StreamingAssets/tempDbFile.db";
		
	//owerwrite any existing files
	File.Copy (oldDbFileFullPath, tempFileFullPath, true);
		
	//then delete it, which fails with the exception
	File.Delete(tempFileFullPath);
}

Any ideas why this fails?

Something else has your file open, if the StreamingAssets folder is in the project view, perhaps unity hooks into the file with it is first written, i’m not sure what has the file handle, but something does, your exception describes this:

“IOException: Sharing violation on path C:/dev/Assets/StreamingAssets/tempDbFile.db”

For the heck of it, put it into a general folder (C:/temp/) or something and see if the access is still limited due to sharing with another program.

You just add “private” before the path.

File.Delete(“private” + tempFileFullPath);

FYI delete file on IOS - Questions & Answers - Unity Discussions