Author Topic: [SOLVED] Delete file OK; delete dir access denied  (Read 2013 times)


  • New Member
  • *
  • Posts: 14
[SOLVED] Delete file OK; delete dir access denied
« on: October 01, 2021, 06:25:33 pm »
There are over a hundred 'access is denied' threads and I'm sorry to add another.

Weeding out old-ish backups, I wrote a simple prog to delete files from one drive when the same name/content was on a second drive.  DeleteFile( name ) worked just fine, and took a few thousand files off my USB memory stick.

That left some empty directories, which I also wanted to delete.  Irritatingly the function RemoveDir( name ) returned false and did not carry out the removal.  I tried name with and without the final slash.

RemoveDirUTF8 and DeleteDirectory didn't help.  Using
    RmDir( name );
    IOresult ...
I turned up the error code 5, Access is Denied.

I cannot see why I can delete files but not dirs on the same (USB) drive.

Can anyone shine a light on this please?

Windows 10, up to date.  Lazarus 2.0.12.  Unit is headed {$mode objfpc}{$H+}.
« Last Edit: October 02, 2021, 05:20:33 am by lorenzo »


  • Sr. Member
  • ****
  • Posts: 432
Re: Delete file OK; delete dir access denied
« Reply #1 on: October 01, 2021, 06:51:59 pm »
In the directories;
-Hidden Files
-Are you sure there are no Hidden Operating System Files?

For manual control ;
Control Panel - File Explorer Options-View Title
You can review the options below.
If Ide=Lazarus 2.0.10 32 Bit and Os=Win 10 Home 64 Bit then Get up and do something useful! Because God is the helper of those who start again;


  • New Member
  • *
  • Posts: 14
Re: Delete file OK; delete dir access denied
« Reply #2 on: October 02, 2021, 05:19:46 am »
That's it, loaded.  Thank you.  I feel stupid for not having thought of it before.

In turns it raises the question why FindFirst etc failed to turn up the files.  I have found a useful thread on that point so I have more work to do and more to learn.  Meanwhile I am marking this thread solved.

Thanks again.


TinyPortal © 2005-2018