MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / delete

Function delete

src/commoncode/fileutils.py:564–578  ·  view source on GitHub ↗

Delete a directory or file at `location` recursively. Similar to "rm -rf" in a shell or a combo of os.remove and shutil.rmtree. This function is design to never fails: instead it logs warnings if the file or directory was not deleted correctly.

(location, _err_handler=_rm_handler)

Source from the content-addressed store, hash-verified

562
563
564def delete(location, _err_handler=_rm_handler):
565 """
566 Delete a directory or file at `location` recursively. Similar to "rm -rf"
567 in a shell or a combo of os.remove and shutil.rmtree.
568 This function is design to never fails: instead it logs warnings if the
569 file or directory was not deleted correctly.
570 """
571 if not location:
572 return
573
574 if os.path.exists(location) or filetype.is_broken_link(location):
575 if filetype.is_dir(location):
576 shutil.rmtree(location, False, _rm_handler)
577 else:
578 os.remove(location)

Callers 6

create_html_appFunction · 0.90
clearMethod · 0.90
_rm_handlerFunction · 0.85
delete_ifMethod · 0.85
shiftMethod · 0.85
popMethod · 0.85

Calls 3

is_dirMethod · 0.80
removeMethod · 0.65
existsMethod · 0.45

Tested by

no test coverage detected