1

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
  • 1
    To delete a file you need write permission in the directory not the file. To debug code we need a reproducabke example is the full code. And for code passing in a function then splitting to call that function is not good style. Lastly programming questions are for stack overflow but first read it’s faq and how to ask a question as this fails in many ways. – Mark Mar 8 at 18:22
  • If you want help with deleting invisible files/directories, please add some details about the directory, it's permissions, error messages you get etc. If you want help in debugging the code, please comment or flag, we can then move the question to StackOverflow. – nohillside Mar 9 at 9:38
  • @Mark Debugging the code isn't my goal here ,i just used it hoping it will fix my problem , i included it because it showed me new output i have never seen before which is the "ghost " of non existing files inside these folder , this is mainly macOS related problem , there no logic to post it on stack overflow Lastly updated the question with folders permissions and it's contents and the exact python script it used , hope you could help me – amryadam Mar 9 at 12:34
  • @nohillside I updated the post with folders permission and error rm & rmdir output , and i don't need to debug the code i just want to show it's new error output – amryadam Mar 9 at 12:41
  • Can you also run ls -@d a b f to show the extended attributes of these directories? Not that I think the cause the issue, but they might give a clue on where the problem comes from. – nohillside Mar 9 at 12:57
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .