제목: 파일 이름과 관련된 상세 설명과 파이썬 샘플 코드
파일 이름은 파일에 대한 식별자로 사용되는 문자열입니다. 파일 이름은 파일을 생성, 열거나 다른 작업에서 사용할 수 있습니다. 파이썬에서는 파일 이름을 다루기 위해 `os` 모듈을 사용할 수 있습니다.
아래는 파일 이름과 관련된 파이썬 샘플 코드입니다:
```python
import os
# 현재 작업 디렉토리 가져오기
current_directory = os.getcwd()
print("현재 작업 디렉토리:", current_directory)
# 파일 경로 합치기
file_path = os.path.join(current_directory, "example.txt")
print("파일 경로:", file_path)
# 파일 확장자 가져오기
file_extension = os.path.splitext(file_path)[1]
print("파일 확장자:", file_extension)
# 파일 이름 변경하기
new_file_path = os.path.join(current_directory, "new_example.txt")
os.rename(file_path, new_file_path)
print("파일 이름 변경 완료")
# 파일 삭제하기
os.remove(new_file_path)
print("파일 삭제 완료")
```
위의 코드에서는 `os` 모듈을 사용하여 현재 작업 디렉토리를 가져오고, 파일 경로를 합치고, 파일의 확장자를 가져오고, 파일 이름을 변경하고, 파일을 삭제하는 방법을 보여줍니다.
추가로 `os.path` 모듈에는 파일과 관련된 다양한 기능이 있으니 필요에 따라 해당 모듈을 확인해보시기 바랍니다.
더 많은 정보를 원하실 경우 파이썬 공식 문서의 `os` 모듈 문서를 참조하세요: [https://docs.python.org/3/library/os.html](https://docs.python.org/3/library/os.html)
댓글