반응형
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 |
'file, directory' 카테고리의 다른 글
Python - with open 파일 쓰기 (file write) (0) | 2022.12.30 |
---|---|
Python - folder 제거(remove) with os(import) (0) | 2022.12.29 |