Question by
ItzChris92 · Aug 28, 2018 at 10:20 PM ·
c#file-iodirectory
Why does this file count always return 0?
DirectoryInfo dir = new DirectoryInfo(Application.persistentDataPath + "/MageRunner");
DirectoryInfo[] files = dir.GetDirectories("*.*");
int x = 0;
for (int i = 0; i < files.Length; i++)
{
if (files[i].Extension.Equals(".pd", StringComparison.OrdinalIgnoreCase))
{
i++;
x++;
}
}
Debug.Log("Player File(s) found: " + x);
As the question says... x is always debugging as zero, even though I have a file at the specified path. I know the filePath is correct as it is the same path I used to save the file in the first place.
Comment
Best Answer
Answer by Bunny83 · Aug 29, 2018 at 05:48 AM
GetDirectories only returns directories and no files. The GetFiles method(s) return only the files in the directory.