Invalid file hand error received when trying to delete files

Hi, I'm a software developer and from within an application, I'm trying to delete a directory tree. Sometimes this does not work and when it doesn't work, I finally found out that it's an invalid file handle error. At least that's what Icacls says.

I have tried many different ways to delete the directory structure, but none will work, but oddly enough, if you try to delete the directory tree outside of the application with windows explorer it will work fine. Even with the application up and running.

I've made sure that nothing in the application has a hold on any of the directories or files.

Does ANYONE know a command line to run to reset those attributes for a whole directory tree?

I would appreciate any help!
3 answers Last reply
More about invalid file hand error received delete files
  1. rmdir from a elevated command prompt
  2. thanks man... will give it a try. I used "RM -rf" but that didn't work.
  3. Ok... if anyone else runs into this, I was able to come up with something that made things work. Take a look at Icacls and the things it can do. Here are the commands that I ran in my application that might help someone. NOTE: AppPath + "\Output" and inPath are the same thing and they are both talking about a directory.

    s.Execute("takeown /f " + AppPath + "\Output")

    s.Execute("Icacls " + inPath + " /verify /t /c /l /q")

    s.Execute("Icacls " + inPath + " /reset /t /c /l /q")

    s.Execute("Icacls " + inPath + " /grant Administrator:(D,WDAC) /inheritance:e|" + inPath)

    The first thing I do is take ownership of the directory (I'm an admin)

    next, verify: finds all files whose ACL is not in canonical form or whose
    lengths are inconsistent with ACE counts.

    then, reset: replaces ACLs with default inherited ACLs for all matching files.

    and last, grant permission: Will grant the user Administrator Delete and Write DAC permissions to file.

    After doing all of the above, I don't have a problem deleting the directory, even if some of the file the attributes are mangled.

    So, I hope this helps someone.
Ask a new question

Read More

Windows Explorer Software Windows 7