0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ディレクトを掘っていき、ディレクトリパス+ファイル名の一覧を作成する

Last updated at Posted at 2020-11-13

ディレクトリ掘っていって、ディレクトリパス+ファイル名の一覧を作成したい時がごく稀にたま~によくあるのでメモ的に残しておきます。

ディレクトリ+ファイルのリスト作成のサンプル

find * -type f

で出来ます。 @angel_p_57 さんありがとうございます!!

今回のディレクトリ構成

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

過去の苦労

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

再帰関数を使えばもう少しうまく書けるかもしれない。
つよつよエンジニアの変態ワンライナーの人がいたら教えてください。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?