1
$\begingroup$
train_dir= '../input/train'    
for file in os.listdir(train_dir):
    print(file)

I am trying to get all the file names in a directory called "train", from a Kaggle dataset.

However, using the above code I just get a return of the folder "train", instead of all the images in the folder "train".

If I repeat the code above using:

data_dir = '../input'    
for file in os.listdir(data_dir):
    print(file)

Then, it works correctly, it outputs the folder "train", the file "train.csv", the file "sample_submission.csv" and the folder "test" correctly.

Hence, I am quite puzzled why it doesn't work in the first case.

Thanks a lot. I am working directly on the Kaggle kernel by the way.

$\endgroup$
1
$\begingroup$

Usually a simple

import os
print(os.listdir("../input"))

works pretty well. Modify as required

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.