- Home /
File.Delete problems with Application.CaptureScreenshot
I want to take some screenshots and then delete some screenshots.
How do I control where these screens are placed --in what directory and how do I delete them. Right now they are just placed in the assets folder (in the editor) if I use Application.CaptureScreenshot. Can I place them wherever I want.
I'd like to place them all in a folder and then delete the folder. Alternatively I can delete them all separately but I'm having trouble finding the path to the files so I can use the System.IO's File.Delete(path);
I'm not sure if I have to put file:// in front or not. I'm using Application.dataPath to find the file.
Can someone clarify or provide a unity code example for System.IO File.Delete(path); I know the file path changes depending on whether it's iphone, or editor.
Thanks, Dan
Answer by rutter · Mar 14, 2012 at 08:34 PM
Unity script reference: Application.CaptureScreenshot()
According to that page, you can pass a full path. You could use something like Path.Combine()
with Application.persistentDataPath and your desired screenshot name.
Instead of deleting old screenshots, why not just append a number to the filename? Or a timestamp?
If you're sure that you want to delete files programmatically, you could use functions like File.Delete()
with Directory.GetFiles()
Oh you're right. I didn't see the path. Just the filename. Thanks.
Answer by bilal12 · Jan 03, 2018 at 05:31 AM
private int Screen_Shot_Count = 0; private string Screen_Shot_File_Name; Screen_Shot_Count++;
Screen_Shot_File_Name = "Screenshot_" + Screen_Shot_Count + System.DateTime.Now.ToString("_yyyy-MM-dd") + ".png";
Application.CaptureScreenshot ("C:/img/" + Screen_Shot_File_Name);
create an 'img' folder in 'C', it will save your screenshot there @dansav
create an 'img' folder in your 'C' and it will store your image into this older @dansav