# Is there any means of Importing folder with images( .jpeg) directly?

I am using Mathematica for training dataset of fruits, for which i need to import the collection of images. Can we import a folder with images directly or Do we need to import each image in iteration format?

Import[FileNameJoin[{"Path", "To", "Directory", "*.jpeg"}], "JPEG"] is undocumented but will work (for now, subject to change).

I recommend perhaps FileSystemMap for this task. Simply Import[#, "JPEG"] & /@ FileNames["/Path/To/Directory/*.jpeg"] will work just fine as well.

• Thank you so much for your Assistance..!! I tried the same with map function. Map[Import, FileNames["*_100.jpg", location]] – Azam Jainullabudin Mohamed Dec 6 '18 at 19:49

afaik. there is no easier way than doing

images = {}
names = FileNames[pattern,{directory}]
Do[AppendTo[images = Import[fileName]], {fileName, names}]


with

pattern = "*.png"
directory = "YourDirectoryName"


The code is untested but should work. Sadly i cannot easily test the code lacking such directory.

code from my old question (modified): DumpSave'ing while lengthy program runs

• This is a bit over complicated, please see my response. – GenericAccountName Nov 9 '18 at 21:07
• @GenericAccountName Good call to simplify that Do loop, i didn't have time to think about that. I made so many variables for the code to be readable. Thanks for pointing out the FileSystemMap, it seems very usefull. – Gladaed Nov 13 '18 at 12:26