How to store images path in csv file ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to store images path in csv file ?

I have a folders which contains images and want to stores all images path of different folders in csv file. Can anyone help me please?

30th Nov 2020, 3:32 AM
Sachin Kumar Gupta
Sachin Kumar Gupta - avatar
3 Answers
+ 3
S.k. Gupta , have you done a try by yourself first? If not, please do so. As a hint: - import the python module >os< and from this use >walk<. With this you will be able to get all paths and filenames. - To store these paths / filenames in a csv file you can use the python module >csv< to create the file. Happy coding!
30th Nov 2020, 6:17 AM
Lothar
Lothar - avatar
+ 2
S.k. Gupta , using listdir() returns everything that a directory contains: - files - directories (I am not sure if you want to read through a storage device and get files from all subdirectories = directory tree? This is something else. in this case see sample in python docs : https://docs.python.org/3.8/library/os.html?highlight=walk#os.walk ) If you want to get files and directory separated, you can use: - walk from os module An other possible way is to use module glob. It enables you to use wildcards to define file extensions.
30th Nov 2020, 9:40 AM
Lothar
Lothar - avatar
0
Lothar , yes i tried by os.listdir() but this returned folders name and not gone in each folder and return image path.
30th Nov 2020, 6:46 AM
Sachin Kumar Gupta
Sachin Kumar Gupta - avatar