|
Preface: colleagues encountered a problem and needs to find the file in 7000 tens of thousands of documents, messy. I checked the Python relevant information, although not completely resolved, but there are still things recorded.
First, for a folder through the file, os.walk can be broken. If multiple folders, then, with isdir, isfile and other functions can be broken (parameter optional):
for i in os.walk (os.getcwd (), topdown = True, onerror = None, followlinks = False):
print i
os.path under judging function:
exists () Specifies the path (file or directory) exists
isabs () Specifies whether the path is an absolute path
isdir () Specifies whether the path exists and is a directory
isfile () Specifies whether a file exists and the path is
islink () Specifies whether the path exists and is a symbolic link
ismount () Specifies whether the path exists and is a mount point
samefile () whether two paths point to the same file name
Such returns i [3] for the list of file names, but I do not know what order, it is necessary to sort based on the file information, and to see how you need, how to sort.
For example, to sort the file has access time:
for i in os.walk (os.getcwd (), topdown = False):
for j in i [2]:
print j, os.path.getctime (j)
In os.path, the following functions on the file information:
getatime () Returns the last access time (float Seconds)
getctime () returns the file creation time
getmtime () returns the most recent file modification time
getsize () Returns the file size (in bytes)
abspath () returns the absolute pathname
normpath () path specification string
Obtain specific information, like the rest of the deal. sorted sorting function can be broken, the focus is not here, temporarily introduced. |
|
|
|