Deleting empty Directory with File’s Ghosts

deletinghomebrewpythonterminal

I am trying to delete bunch of directories appearing to be empty

    amr@MacBook ~/folders> ls -la -R
total 24
drwxrwxrwx   6 amr  staff    192 Mar  9 14:37 .
drwx---r-x+ 40 amr  staff   1280 Mar  9 14:12 ..
-rw-r--r--@  1 amr  staff  10244 Mar  9 14:37 .DS_Store
drwxrwxrwx@  5 amr  staff    160 Feb 27 19:06 a
drwxrwxrwx@  5 amr  staff    160 Mar  9 14:01 b
drwxrwxrwx@  3 amr  staff     96 Feb 27 19:00 f

./a:
total 0
drwxrwxrwx@ 5 amr  staff  160 Feb 27 19:06 .
drwxrwxrwx  6 amr  staff  192 Mar  9 14:37 ..

./b:
total 0
drwxrwxrwx@ 5 amr  staff  160 Mar  9 14:01 .
drwxrwxrwx  6 amr  staff  192 Mar  9 14:37 ..

./f:
total 0
drwxrwxrwx@ 3 amr  staff   96 Feb 27 19:00 .
drwxrwxrwx  6 amr  staff  192 Mar  9 14:37 ..

amr@MacBook ~/folders> rm -r a b f
rm: a: Directory not empty
rm: b: Directory not empty
rm: f: Directory not empty
amr@MacBook ~/folders> rmdir *
rmdir: a: Directory not empty
rmdir: b: Directory not empty
rmdir: f: Directory not empty

with every possible way i could find like this , boot into recovery and trying from there , tried mv to USB and formate it with not like either and got the same message "Directory not empty" until i found this python script

import os, stat, shutil

   def remove_readonly(fn, path, excinfo):
#removes readonly tag from files/folders so they can be deleted
if fn is os.rmdir:
    os.chmod(path, stat.S_IWRITE)
    os.rmdir(path)
elif fn is os.remove:
    os.chmod(path, stat.S_IWRITE)
    os.remove(path)

shutil.rmtree('/Users/amr/folders/'',
          onerror=remove_readonly)

which gave me a new output

OSError: [Errno 2] No such file or directory: 'folders/a/0c26d4c3daf0b26cd91366caf1df3eca0bad5611e9742a0f8b409d6b80fc6a53--pixman-0.38.0.mojave.bottle.tar.gz'

other directory

OSError: [Errno 2] No such file or directory: 'folders/b/libpixman-1.dylib'

the thing is those files i already deleted manually when i tried to fix brew but wasn't able to delete the empty directory directory

Update :
it seem that somehow i deleted the files but not it's extended attribute and when i try to deleted folder it tries to delete files with it's attribute but it found the attribute but not the file

sudo xattr -rc *
Password:
xattr: No such file: a/784a181552c10546bdab9595d963a36fa65d6e17cc04609285349cb81be623b9--harfbuzz-2.3.1.mojave.bottle.tar.gz.incomplete.lock
xattr: No such file: a/pixman.formula.lock
xattr: No such file: a/0c26d4c3daf0b26cd91366caf1df3eca0bad5611e9742a0f8b409d6b80fc6a53--pixman-0.38.0.mojave.bottle.tar.gz.incomplete.lock
xattr: No such file: b/libpixman-1.dylib
xattr: No such file: b/libpixman-1.a
xattr: No such file: b/libpixman-1.0.dylib
xattr: No such file: f/pixman

Best Answer

Move the folder to the trash. Open the trash and right click on the folder. You should see an option to "delete immediately". Select that option and folder should delete.