- Home /
How to simply check if a file exists on the hard drive?
Is there a simple way to check if a file exists in a folder on the user's hard drive (standalone game) without having to create an array of all files in the folder and iterate through it?
Answer by Mike 3 · Jul 01, 2010 at 07:31 PM
You can use File.Exists:
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
Funny enough, the usage is identical in C# and JS
if (System.IO.File.Exists("myfile.txt"))
{
//do stuff
}
Any way to get a quick example of how I would use that in javascript code? I use the Net stuff in my code but I'm still not totally clear on how it integrates so I stumble through until it works.
Dear answer-er: I love you
I spent 2 hours trying to figure out how to do that. Thank you!
thanks. Simple, fast, easy, exacly what I was looking for
(btw you can also import System.IO before running File.Exists)
Your answer
![](https://koobas.hobune.stream/wayback/20220613063635im_/https://answers.unity.com/themes/thub/images/avi.jpg)