Dig the directory and create a list of directory paths + file names

It is very rare that you want to dig a directory and create a ** directory path + file name list **, so leave it as a memo.

Sample of directory + file list creation

find * -type f

You can do it with. Thank you @ angel_p_57! !!

This directory structure

01_hokkaido
└ 001_sapporo
  └xxxxx.jpg
  └xxxxx.jpg
  └xxxxx.jpg
└ 002_obihiro
└ 003_hakodate
  ⁝
02_aomori
└ 002_aomori
  ⁝
03_iwate
⁝

Past hardships

ls -1 | while read LINE
do
    PREFECTURE=${LINE}
    ls -1 "${PREFECTURE}" | while read LINE2
    do
        CITY="${LINE2}"
        ls -1 "${PREFECTURE}"/"${LINE2}" | while read LINE3
        do
            FILE="${LINE3}"
            echo "${PREFECTURE}"/"${CITY}"/"${FILE}"
        done
    done
done

You might be able to write it a little better with a recursive function. Please let me know if there is a metamorphosis one-liner person of Tsuyotsuyo engineer.

Recommended Posts

Dig the directory and create a list of directory paths + file names
[Note] Import of a file in the parent directory in Python
Python: Create a dictionary from a list of keys and values
Get the filename of a directory (glob)
For Windows: Get a list of directories and files under a specific directory.
Replace the directory name and the file name in the directory together with a Linux command.
Test & Debug Tips: Create a file of the specified size in Python
View the full path (absolute path) of a file in a directory in Linux Bash
[python] Create a list of various character types
Make a copy of the list in Python
A discussion of the strengths and weaknesses of Python
[Python] Create a list of date and time (datetime type) for a certain period
Zip-compress any file with the [shell] command to create a file and delete the original file.
How to get a list of files in the same directory with python
Extract and list personal names and place names in the text
Automatically determine and process the encoding of the text file
Make a note of the list of basic Pandas usage
Create a batch of images and inflate with ImageDataGenerator
[Python] Get the list of ExifTags names of Pillow library
Output the output result of sklearn.metrics.classification_report as a CSV file
Make a list of latitude and longitude and convert UTM coordinates at once → File output
Create a shape on the trajectory of an object
Create a docx file with thumbnails of photos in the folder pasted with the Python python-docx library and the free software "Reduction only."
[Golang] Command to check the supported GOOS and GOARCH in a list (Check the supported platforms of the build)
Spit out a list of file name, last modified date and character code in python3
Extract only the sound of a specific instrument from a MIDI file and make it a separate file
Get the trading price of virtual currency and create a chart with API of Zaif exchange
[Ubuntu] How to delete the entire contents of a directory
Save the pystan model and results in a pickle file
Scraping the Excel file of the list of stores handling regional coupons
[Python] Create a date and time list for a specified period
Get the number of specific elements in a python list
Create a partition and then install the Raspberry Pi OS
A rough summary of the differences between Windows and Linux
Create a new list by combining duplicate elements in the list
Create a correlation diagram from the conversation history of twitter
Extract the value of dict or list as a string
How to connect the contents of a list into a string
Read and write a file
Create a dummy data file
Linux file and directory permissions
Write and read a file
Create and list Django models
Create a directory with python
A story about predicting prefectures from the names of cities, wards, towns and villages with Jubatus
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
[Python scraping] Output the URL and title of the site containing a specific keyword to a text file
I want to extract the tag information (title and artist) of a music file (flac, wav).
Output the key list included in S3 Bucket to a file
Process the contents of the file in order with a shell script
Overview of how to create a server socket and how to establish a client socket
Set the last modified date of the child file to the modified date of the parent directory
Search the file name including the specified word and extension in the directory
Create a shell script to run the python file multiple times
On Linux, the time stamp of a file is a little past.
If you give a list with the default argument of the function ...
I tried to create a list of prime numbers with python
Specify or create a python folder and then save the screenshot.
[Go] Create a CLI command to change the extension of the image
Save the Pydrive authentication file in a different directory from the script
I tried to get a list of AMI Names using Boto3