EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Enumerate directory

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
Posted: 08/13/2014 07:34:50
by pnina (Standard support level)
Joined: 11/20/2013
Posts: 36

I read the documentation about directory enumeration and from what I understood, the first call, when EnumerationInfo.UserContext.Equals(IntPtr.Zero), I should load the list of sub files and folders for the current directory in order to use it in subsequent enumeration calls.

If I'm using the VDisk sample, then I should fill the Context of the given directory with my sub files and folders (converted to VirtualFile objects).

What I am doing in general is:
if (EnumerationInfo.UserContext.Equals(IntPtr.Zero))
    pInfo = new ENUM_INFO();
    gch = GCHandle.Alloc(pInfo);
    EnumerationInfo.UserContext = GCHandle.ToIntPtr(gch);
    FindVirtualFile(DirectoryInfo.FileName, ref vdir);
    pInfo.vfile = vdir;

    myApp.GetSubFilesAndFolders(ref files, ref directories);
   foreach (myFile directory in directories)
      VirtualFile vSubDir = new VirtualFile(directory.Name);
      vSubDir.Attributes = System.IO.FileAttributes.Directory;
      vSubDir.CreationTime = vSubDir.LastAccessTime = vSubDir.LastWriteTime = directory.LastModified;
   foreach (myFile file in files)
      VirtualFile vSubFile = new VirtualFile(file.Name);
      vSubFile.OriginalFileSize = file.Size;
      vSubFile.CreationTime = vSubFile.LastAccessTime = vSubFile.LastWriteTime = file.LastModified;
   pInfo = (ENUM_INFO)GCHandle.FromIntPtr(EnumerationInfo.UserContext).Target;
   vdir = pInfo.vfile;

But since I'm using pInfo.vfile.AddFile, then every time the enumeration is done, the number of files increases.
I tried clearing the context of the virtual file every time, so that I will always have the right amount of files inside, but then it caused an "Handle is not initialized." Error inside ReadFile event.

I tried to build the logic according to the explanation here: https://www.eldos.com/cbfs/articles/5335.php
I think I'm missing something here. When exactly I should load the sub files? Should it happen every time or just once when the directory is still empty?
Posted: 08/13/2014 07:39:55
by Eugene Mayevski (EldoS Corp.)

You are basing your code on the sample which you don't fully understand. In this situation it's better to study Mapper sample (as it's much simpler) and base your work on it.

VDisk is indeed a complicated sample. In general the samples are provided not as templates at all and should not be used as such. They *illustrate* the use of the API. We don't provide templates in any of our products.

Sincerely yours
Eugene Mayevski



Topic viewed 1795 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!