- Home /
Debug Statement Doesn't Work?
Hi guys, I've got this code
string filePath = PlayerPrefs.GetString("Igloo Install Location") + "\\IglooWarper";
if (File.Exists(filePath))
{
UnityEngine.Debug.Log(filePath);
}
Process.Start(PlayerPrefs.GetString("Igloo Install Location") + "\\IglooWarper"); //Needs the full file path to launch; defined in registry.
The Process.Start line works fine, but the lines above, with the Debug statement won't get hit. It fires if !File.Exists but I know that it does, obviously, because it's launching.
using system.IO;
Any ideas? Thanks.
Answer by Bunny83 · Feb 05, 2019 at 04:21 PM
Most likely because "IglooWarper" is not a valid file name. If it's an executable file the full file name is "IglooWarper.exe". Starting a process goes through the OS shell which will resolve the path of the file automatically. However "File.Exists" only checks valid file names. You could have several files with the same name but different extensions. Though the extension is part of the filename. So if you have the files:
IglooWarper.exe
IglooWarper.txt
IglooWarper.doc
If you ask if "IglooWarper" exists this can't be answered with "yes" since there is no file without extension. However if the OS should start a process named "IglooWarper" it first tries to run "IglooWarper" (which will fail) and then it assumes "IglooWarper.exe". So working with files and starting a process are two different things.
Hi, thanks for the feedback. I've also tried putting .exe at the end, still no luck.
I did, however, write out another file path word for word and that launched the file as intended, but I need customisable file paths (hence the PlayerPrefs stuff). It wouldn't have to do with the fact that the file path is first stored in the Prefs and then read from it, would it?