1

Closed

RemoteDirectory.FindFiles works wrong

description

RemoteDirectory.FindFiles enumerate directories as well as files.
I updated code the following way and get correct result:
public static string[] GetDirectories(RemoteDevice device, string path, string searchPattern)
{
  return EnumFiles(device, path, searchPattern, false, true);
}
 
public static string[] GetFiles(RemoteDevice device, string path, string searchPattern)
{
  return EnumFiles(device, path, searchPattern, true, false);
}
 
private const int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
 
private static string[] EnumFiles(RemoteDevice device, string path, string searchPattern, bool files, bool folders)
{
  int foundCount = 0;
  IntPtr findDataArray;
  if (0 == device._session.CeFindAllFiles(Path.Combine(path, searchPattern), 0x0081, ref foundCount, out findDataArray))
  {
    device.ThrowRAPIException();
  }
 
  System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(foundCount);
  try
  {
    for (int i = 0; i < foundCount; i++)
    {
      IntPtr current = (IntPtr)((long)findDataArray + i * Marshal.SizeOf(typeof(CE_FIND_DATA)));
      CE_FIND_DATA fds = (CE_FIND_DATA)Marshal.PtrToStructure(current, typeof(CE_FIND_DATA));
      if ((fds.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
      {
        if (folders) list.Add(fds.Name);
      }
      else
      {
        if (files) list.Add(fds.Name);
      }
    }
  }
  finally
  {
    device._session.CeRapiFreeBuffer(findDataArray);
  }
  return list.ToArray();
}
Closed Aug 2, 2009 at 3:48 AM by dahall
Fixed in source drop from 2009-08-01. Will roll into next released download.

comments