# Import files AppendTo and ToExpression

I have a list of files all indexed as filename1,filename2,filename3,... up to 50, all in the same directory, and I wanted an AppendTo them to a list and ToExpression in index order 1,2,...,50.

Does anyone know of a good method to do this? Thanks!

• You can obtain a list of filenames, e.g., by list = FileNames[FileNameJoin[dir, "filename*"]] where dir is a string specifying the directory. Afterwards you can Map anything over that list, for example, Import... – Henrik Schumacher Feb 4 '19 at 18:08
• Thanks. will it do so indexed numerically? the order it is stored is crucial – MKF Feb 4 '19 at 18:11
• Or will it do something like store filename10,11,12,...,19,1,20,21,...,29,2? This is the index order if you consider FileNames and I fear therefore it will not order my index correctly – MKF Feb 4 '19 at 18:12
• The order is the typical lexicographical order of strings. So, yes, that may happen. That's why one should enumerate file names with leading zeroes. – Henrik Schumacher Feb 4 '19 at 18:12
• Thanks @Henrik How could this be avoided therefore? – MKF Feb 4 '19 at 18:14

Table[FileNameJoin[{dir,"filename" <> IntegerString[i]}], {i, 1, 50}]

where dir is a string containing the path to said directory.
• So I tried Do[AppendTo[ ToExpression[Import["filename" <> IntegerString[i], "List"]], completelist], {i, 1, 50}] but to no avail – MKF Feb 4 '19 at 18:33
• You have reverse the syntax of AppendTo Try completelist = {}; Do[ AppendTo[completelist, ToExpression[Import["filename" <> IntegerString[i], "List"]]], {i, 1, 50}] or something similar... – Henrik Schumacher Feb 4 '19 at 18:40