본문으로 바로가기
728x90

모듈 설치

pip install send2trash

(py36) PS C:\Users\Desktop\python_\send2trash_> pip install send2trash
Collecting send2trash
  Using cached Send2Trash-1.5.0-py3-none-any.whl (12 kB)
Installing collected packages: send2tras
Successfully installed send2trash-1.5.0

 

예제

import os
import send2trash

file_list = os.listdir()
print(file_list)

for file in file_list:
    if file.find('test') > -1:
        if os.path.isdir(file):
            print(f'Dir : {file}')
            print(f'  ㄴ{os.listdir(file)}')
        else:
            print(f'File : {file}')
        send2trash.send2trash(file)

file_list = os.listdir()
print(file_list)
더보기
['.vscode', 'ex.py', 'testdir', 'testdir2', 'testdir3', 'testfile']
Dir : testdir
  ㄴ[]
Dir : testdir2
  ㄴ['testdir2-1', 'testfile2']
Dir : testdir3
  ㄴ['testfile3']
File : testfile
['.vscode', 'ex.py']