FindFirstFile returns access denied

I am trying to create a robust recursive delete folder function.

It works very well in normal directories.

The problem occurs when I create a "hardcore", for example:

C: \ test \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ x \ ... \ x \ x \ x

The length of this order is about 25,000 (less than the MSDN limit: 32,767). I basically created this directory recursively until the CreatDirectory function exited.

Now the strangest thing is that my function is able to delete 2 directories, and FindFirstFile with 0x5:

\\?\C:\test\x\ ... \x\x\x\*.* < no error \\?\C:\test\x\ ... \x\x\*.* < no error \\?\C:\test\x\ ... \x\*.* < access denied 

(I can restart it, the application slowly iterates over the folder, 2 by 2, probably until the path length becomes quite small)

I run FindFirstFile to check if the folder is empty.

  • Are there any restrictions that are less documented?
  • FindFirstFile just not working? (Is it buggy?)
  • Am I missing some kind of NTFS permission?
  • Something else...

EDIT: IMPORTANT NOTE: If I run the program step by step slowly ... then nothing will work.

+6
source share
1 answer

You are probably experiencing something like an antivirus scanner, indexer, or continuous backup solution that contains a directory descriptor. If the indexing service is configured to index this folder, for example.

Attempting to delete a folder or file that is open except for the FILE_SHARE_DELETE flag will result in ACCESS_DENIED.

To confirm this, use Process Monitor to see how everything that matches your path opens and closes.

(Of course, also confirm that you called FindClose).

+7
source

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


All Articles