티스토리 뷰

shutil.rmtree(path[, ignore_errors[, onerror]])

Delete an entire directory tree; path must point to a directory (but not a symbolic link to a directory). If ignore_errors is true, errors resulting from failed removals will be ignored; if false or omitted, such errors are handled by calling a handler specified by onerror or, if that is omitted, they raise an exception.

If onerror is provided, it must be a callable that accepts three parameters: functionpath, and excinfo. The first parameter, function, is the function which raised the exception; it will be os.path.islink()os.listdir(),os.remove() or os.rmdir(). The second parameter, path, will be the path name passed to function. The third parameter, excinfo, will be the exception information return by sys.exc_info(). Exceptions raised by onerror will not be caught.

Changed in version 2.6: Explicitly check for path being a symbolic link and raise OSError in that case.

출처 : https://docs.python.org/2/library/shutil.html



1. 소스입니다. 주석으로 설명을 대체하겠습니다.


2. 스크립트가 잘 동작하는지 보기 위해서 폴더들을 생성하고, 폴더 안에 파일들을 무작위로 넣어 보겠습니다.




3. 스크립트를 실행한 후의 모습입니다.


위 스크립트를 응용하면 재미있는 발상들이 쏟아져 나오네요 :)


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함