これがあなたが上記の質問で得ているものであるかどうかは完全にはわかりません。しかし、最初に、4つのフォルダーのenumerate()
インデックスと名前を保持できるようにするために使用したいようです。ただし、上記のコメントに基づいて、各サブフォルダー内の各ファイルのすべてのコンテンツを実際に追加するには、実際には追加のforループが必要になると思います。以下はトリックを行う必要があります。
また、ディクショナリキーはで始まる1
ため、列挙型インデックスが0で始まるという事実を考慮する必要があることにも注意してください。
# Here, enumerate gives back the index and element.
for i,file_name in enumerate(sorted(os.listdir(full_subdir_name))):
full_file_name = os.path.join(full_subdir_name,file_name)
# Here, 'elem' will be the strings naming the actual
# files inside of the folders.
for elem in sorted(os.listdir(full_file_name)):
# Here I am assuming you don't want to append the full path,
# but you can easily change what to append by adding the
# whole current file path: os.path.join(full_file_name, elem)
namelist[i+1].append(elem)