Can I read whole NTFS directory tree into RAM at o

2019-09-05 20:44发布

Since this quesiton yielded no useful answers and some comments please see my other question that got spot on anwer: How exactly "Everything Search" can give me immediately searchable list of 2bln files on my 4TB HDD in less than 10 seconds?

Only way I know of reading directories is to recursively descend into each directory but that's too slow if I want to find file anywhere on the whole disk quickly.

There's windows program "Everything Search" http://www.voidtools.com/ that does that faster than I assume is possible by recursive descent (it reads filenames of almost 2bln files on 4TB HDD in less than 10 seconds).

I know I could build index ahead of time but can it be done just by reading whole directory tree of a disk into ram in one operation and parsed there?

EDIT

Since my question proved to be confusing here's what I want to do:

https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

// For Directory::GetFiles and Directory::GetDirectories 
// For File::Exists, Directory::Exists 
using namespace System;
using namespace System::IO;
using namespace System::Collections;

// Insert logic for processing found files here. 
void ProcessFile( String^ path )
{
   Console::WriteLine( "Processed file '{0}'.", path );
}


// Process all files in the directory passed in, recurse on any directories  
// that are found, and process the files they contain. 
void ProcessDirectory( String^ targetDirectory )
{

   // Process the list of files found in the directory. 
   array<String^>^fileEntries = Directory::GetFiles( targetDirectory );
   IEnumerator^ files = fileEntries->GetEnumerator();
   while ( files->MoveNext() )
   {
      String^ fileName = safe_cast<String^>(files->Current);
      ProcessFile( fileName );
   }


   // Recurse into subdirectories of this directory. 
   array<String^>^subdirectoryEntries = Directory::GetDirectories( targetDirectory );
   IEnumerator^ dirs = subdirectoryEntries->GetEnumerator();
   while ( dirs->MoveNext() )
   {
      String^ subdirectory = safe_cast<String^>(dirs->Current);
      ProcessDirectory( subdirectory );
   }
}

int main( int argc, char *argv[] )
{
   for ( int i = 1; i < argc; i++ )
   {
      String^ path = gcnew String(argv[ i ]);
      if ( File::Exists( path ) )
      {

         // This path is a file
         ProcessFile( path );
      }
      else 
      if ( Directory::Exists( path ) )
      {

         // This path is a directory
         ProcessDirectory( path );
      }
      else
      {
         Console::WriteLine( "{0} is not a valid file or directory.", path );
      }

   }
}

I want to get same information but without calling Directory::GetDirectories multiple times. Solution I'm looking for doesn't look anyway like this code. This code is just illustration of what information I want read of the disk (names of all files in directories) not how I'd like to do it (I don't want recursion and as many system calls as there are directories).

EDIT 2 (For the people that consider this question too broad):

I'm asking how to do that either on Windows or Linux operating systems. I'll accept answer in any language because I'm most interested what system calls I need to make (and how to parse the results of those calls) to get NTFS directory tree of a whole drive into RAM with fewer system calls than one per each directory on the drive.

I'll also accept the answer that points me to Windows or Linux library that does exactly that.

1条回答
放荡不羁爱自由
2楼-- · 2019-09-05 21:33

if you have sufficient amount of RAM then go ahead and do it. But I recommend you to load disk in parts instead of whole disk that will also improve your time efficiency.

查看更多
登录 后发表回答