Python> Get a list of files in multiple directories> Use glob | Sort by modification time

Operating environment


GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.1.0
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)

bash> TFRerocds conversion of files in multiple directories (individual processing) http://qiita.com/7of9/items/6f6ffdb7dbcebdc8d923 Implementing the process of collecting TFRecords of multiple directories created in.

First, get the file list.

It seems to use glob. http://www.yukun.info/blog/2008/08/python-directory-listdir-glob.html Thank you for the information.

combine_TFRecords_170722.py


import glob

"""
v0.1 Jul. 22, 2017
    - get file list
"""

# codingrule:PEP8

res = glob.glob("../run*/IntField-Y_170709.tfrecords")
for elem in res:
    print(elem)

$ python3 combine_TFRecords_170722.py 
../run366_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run375_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run354_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run362_sphere_g26_m1.4/IntField-Y_170709.tfrecords
../run364_sphere_g26_m1.4/IntField-Y_170709.tfrecords
../run368_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run370_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run376_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run367_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run356_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run372_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run355_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run360_sphere_g26_m1.4/IntField-Y_170709.tfrecords
../run373_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run365_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run369_sphere_g26_m1.45/IntField-Y_170709.tfrecords
../run353_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run357_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run371_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run359_sphere_g26_m1.4/IntField-Y_170709.tfrecords
../run358_sphere_g26_m1.33/IntField-Y_170709.tfrecords
../run374_sphere_g26_m1.5/IntField-Y_170709.tfrecords
../run363_sphere_g26_m1.4/IntField-Y_170709.tfrecords
../run361_sphere_g26_m1.4/IntField-Y_170709.tfrecords

Sort by modification time

(Addition 2017/10/03)

Reference: https://stackoverflow.com/questions/6773584/how-is-pythons-glob-glob-ordered

The order in glob.glob () execution will be the same as ls -U.

Use sort () to sort by modification time.

import os
sorted(glob.glob('*.png'), key=os.path.getmtime)

Recommended Posts

Python> Get a list of files in multiple directories> Use glob | Sort by modification time
Get a list of files in a folder with python without a path
Group by consecutive elements of a list in Python
How to get a list of files in the same directory with python
Get the number of specific elements in a python list
How to get a list of built-in exceptions in python
Try to get a list of breaking news threads in Python.
Display a list of alphabets in Python 3
[python] Get a list of instance variables
[Python] Get a list of folders only
For Windows: Get a list of directories and files under a specific directory.
Get a list of packages installed in your current environment with python
Get a datetime instance at any time of the day in Python
[Python] Get the files in a folder with Python
[Python] Sort the list of pathlib.Path in natural sort
Get the caller of a function in Python
Make a copy of the list in Python
Get a list of Qiita likes by scraping
Get a glimpse of machine learning in Python
Sort list elements in a specified order in Python
[Python] Manipulating elements in a list (array) [Sort]
Get a list of articles posted by users with Python 3 Qiita API v2
Get Unix time of the time specified by JST regardless of the time zone of the server in Python
[python] Get the list of classes defined in the module
Python: Get a list of methods for an object
Get the value of a specific key in a list from the dictionary type in the list with Python
[Python] Rename all image files in a specific folder by shooting date and time
[Python] How to make a list of character strings character by character
Get the value of a specific key up to the specified index in the dictionary list in Python
[Command] Command to get a list of files containing double-byte characters
Get a list of purchased DMM eBooks with Python + Selenium
Developed a library to get Kindle collection list in Python
Since Python 1.5 of Discord, I can't get a list of members
How to get the last (last) value in a list in Python
Get index of nth largest / smallest value in list in Python
A set of script files that do wordcloud in Python3
Get index of nth largest / smallest value in list in Python
Sort by date in python
A simple data analysis of Bitcoin provided by CoinMetrics in Python
Read the standard output of a subprocess line by line in Python
A function that measures the processing time of a method in python
[python] Get the rank of the values in List in ascending / descending order
Sort the file names obtained by Python glob in numerical order
When you want to sort a multidimensional list by multiple lines
How to delete multiple specified positions (indexes) in a Python list
Get the number of readers of a treatise on Mendeley in Python
Extract multiple list duplicates in Python
[Python] Sort iterable by multiple conditions
Handling of JSON files in Python
Sort large text files in Python
Delete multiple elements in python list
Extension of Python by C or C ++ (when there are multiple arguments, when passing a list from the Python side)
Get a capture of the entire web page in Selenium Python VBA
[Python] How to put any number of standard inputs in a list
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Linux] Command to get a list of commands executed in the past
I want to sort a list in the order of other lists
Receive a list of the results of parallel processing in Python with starmap
How to format a list of dictionaries (or instances) well in Python
How to sort by specifying a column in the Python Numpy array.
When specifying multiple keys in python sort