python标准库os模块常用方法

  1. os.listdir(path='.')

Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory. If a file is removed from or added to the directory during the call of this function, whether a name for that file be included is unspecified.
path may be a path-like object. If path is of type bytes (directly or indirectly through the PathLike interface), the filenames returned will also be of type bytes; in all other circumstances, they will be of type str.
返回指定路径目录下的条目名称列表。列表是没有顺序的,不包括特殊路径'.'和'..'。
path-like object
An object representing a file system path. A path-like object is either a str or bytes object representing a path, or an object implementing the os.PathLike protocol. An object that supports the os.PathLike protocol can be converted to a str or bytes file system path by calling the os.fspath() function; os.fsdecode() and os.fsencode() can be used to guarantee a str or bytes result instead, respectively.

import os
for file in os.listdir("/home/weblogic"):
  print(file)
posted @ 2024-08-02 16:38  EPIHPANY  阅读(15)  评论(0)    收藏  举报