python : get list all *.txt files in a directory
This question already has an answer here:
you can use os
, subprocess
and glob
library
os
library example:
import os
os.system("ls *.txt")
this command returned all .txt
file
subprocess
library example:
my_result_command = subprocess.Popen(['ls', '-l'], stdout=log, stderr=log, shell=True)
you can check my_result_command and get all file or .txt
file
glob
library example:
import glob
glob.glob('*.txt')
链接地址: http://www.djcxy.com/p/20042.html
上一篇: Python3从特定目录列出文件