python获取文件名及文件扩展名的方法

import os

file_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获取文件名及文件扩展名的方法)