Feb 6, 2010 at 3:07 AM
Edited Feb 6, 2010 at 3:08 AM
I am using enumfiles to try and get files within a directory on the device.
My "_list" variable is always returning NULL
Here is my code
private void SearchFiles(string searchPath)
FileList _list = device.devrapi.EnumFiles(searchPath + "\\*.*");
foreach(FileInformation file in _list)
if(file.FileAttributes == 16) // Is a directory: recursive search...
SearchFiles(searchPath + "\\" + file.FileName);
else if(file.FileAttributes == 32) // Is a file: add to a list...
clbGames.Items.Add(searchPath + "\\" + file.FileName);
else throw new ArgumentException
("FileAttributes unknown: " + file.FileAttributes, "file.FileAttributes");
In the FOREACH line, the _list throws a NULLREFERENCEEXCEPTION Error - Object reference not set to an instance of an object.
Yes, the searchpath is valid and there are 3 files in the searchpath.
I should also mention the device is PRESENT and CONNECTED from code previous to calling this routine.
Found the issue.
Throughout the program, I use the same searchpath for copying files to the device and copying files from the device (that I know the filename of) without any issues.
However, ENUMFILES is CASE SENSITIVE of the path, while the other routines are not.
I found that my searchpath (which like I said is used throughout the program successfully) had one character in lowercase, but looking on the device, it is uppercase.
I changed that ONE character to uppercase, and now the ENUMFILES returns the files.