python获取文件名及文件扩展名的方法
生活随笔
收集整理的這篇文章主要介紹了
python获取文件名及文件扩展名的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import osfile_list = os.listdir('./')
for item in file_list:print(item)print('file name:',os.path.splitext(item)[0])print('file ext name:', os.path.splitext(item)[1])
?
輸出結果:
F:\wenlong\workspace\WM_SDK_TFI\Tools\test\testcases\task>python addCaseIntoProject.py
addCaseIntoProject.py
file name: addCaseIntoProject
file ext name: .py
new.txt
file name: new
file ext name: .txt
test_task.c
file name: test_task
file ext name: .c
test_task_commuicate.c
file name: test_task_commuicate
file ext name: .c
test_task_timer.c
file name: test_task_timer
file ext name: .c
F:\wenlong\workspace\WM_SDK_TFI\Tools\test\testcases\task>
總結
以上是生活随笔為你收集整理的python获取文件名及文件扩展名的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何将APACHE许可证应用于您的工作
- 下一篇: 用ADC编码PCM数据录制WAV格式音频