How do i index specific file type like .jpg,gif,mp4 and print in .txt file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do i index specific file type like .jpg,gif,mp4 and print in .txt file

I want an algorithm for Printing only the name of the file with file extension Then put them in folder I have tried using is os.system but failed 😅

24th Jan 2019, 2:10 PM
Yash🏁🔘
Yash🏁🔘 - avatar
2 Answers
+ 3
strawdog os.system('dir,c:\\users\\yash\\desktop\\*.jpg')#is working but for filename in os.system('dir,c:\\users\\yash\\desktop\\*.jpg') print(filename) #not working and for filename in gob.iglob(r'c:\\dir\\*.jpg')#not working even i have use variable for getting the data thanku for giving the idea for this > \*.jpg
3rd Apr 2019, 4:09 AM
Yash🏁🔘
Yash🏁🔘 - avatar
+ 1
Use glob module (either alone or along with os module) like this import glob for filename in glob.iglob(r'D:\dir\*.jpg'): print(filename)
24th Jan 2019, 2:40 PM
strawdog
strawdog - avatar