背景示例 背景
os.listdir(path)返回一个列表,该列表中包含path目录下的文件以及文件夹。
查看python官方的说明:
import oshelp(os.listdir)
运行返回:
Help on built-in function listdir in module nt:listdir(path=None) Return a list containing the names of the files in the directory. path can be specified as either str or bytes、 If path is bytes, the filenames returned will also be bytes; in all other circumstances the filenames returned will be str. If path is None, uses the path='.'. On some platforms, path may also be specified as an open file descriptor; the file descriptor must refer to a directory. If this functionality is unavailable, using it raises NotImplementedError. The list is in arbitrary order、 It does not include the special entries '.' and '..' even if they are present in the directory.
示例简单的演示os.listdir(path)的使用:
# jn10010537import ospath="./test"result=os.listdir(path)print(">>>result:",result)
运行如下: