본문 바로가기
file, directory

Python - file 제거(remove) with os(import)

by space father python 2022. 12. 29.
반응형

Code

1
2
3
4
5
6
7
8
import os
 
file = "remove_file.txt"
if os.path.isfile(file):
    os.remove(file)
    print(f"removed file: {file}")
else:
    print(f'There is no {file}')
cs

 

Result

#> python .\file_remove.py
There is no remove_file.txt

#> echo 'creat' > remove_file.txt
#> python .\file_remove.py       
removed file: remove_file.txt