File.Exists returns true, but OpenExisting does not work with DirectoryNotFoundException

I am trying to open a memory mapped file in a subfolder of system volume information. I know and see in the explorer that it exists there, and the path is correct (it is copied from the explorer), and File.Exists for this path returns true, but MemoryMappedFile.OpenExisting does not work with DirectoryNotFoundException. What for? (I have all rights to the folder with information about the system volume and subfolders).

Some codes:

const string filePath = @"C:\\System Volume Information\\Foo\\2.ext"; bool exists = File.Exists(filePath); //is true using (MemoryMappedFile bitmapFile = MemoryMappedFile.OpenExisting(filePath, MemoryMappedFileRights.Read)) //Throws DirectoryNotFoundException { ... } 
+6
source share
2 answers

You need to use MemoryMappedFile.CreateFromFile ("yourPathToFileInDisk", FileMode.Open, "WhateverName") , which opens the file you need. MemoryMappedFile.OpenExisting ("WhateverName") tries to open an existing file with memory mapping.

+3
source

I did not use these APIs, but I believe that you need to copy the file to memory first. Try MemoryMappedFile.CreateFromFile

+1
source

Source: https://habr.com/ru/post/974691/


All Articles