I am not sure if this is the best way of doing it, so the following is not exactly an answer to the question. Here is how I would do it assuming that I have padding.
0 Preparation
data={1,2,3};(*some test data*)
(*exporting to some files*)
Table[Export["myData" <> IntegerString[i, 10, 5] <> ".txt", data], {i,10}];
(*and deleting one to make it a bit more complicated*)
DeleteFile["myData00003.txt"];
Now how to proceed? Check the files.
FileNames[]
{"desktop.ini","Ma musique", "Mes images","Mes vidéos","myData00001.txt",
"myData00002.txt", "myData00004.txt", "myData00005.txt", "myData00006.txt", "myData00007.txt", "myData00008.txt", "myData00009.txt", "myData00010.txt", "test.xls"}
(*Now let us take only the ones that start with the right name*)
fList = Select[FileNames[], (StringMatchQ[#, StartOfString ~~ "myData" ~~ __] &)];
(*or directly using the power of FileNames[]*)
fList = FileNames["myData*"]
{"myData00001.txt", "myData00002.txt", "myData00004.txt", \
"myData00005.txt", "myData00006.txt", "myData00007.txt", \
"myData00008.txt", "myData00009.txt", "myData00010.txt"}
(*If we want the numbers of those we can use regular expressions*)
(*If the lengths are all fixed, StringDrop[] can also work*)
numbers=ToExpression[Flatten[StringCases[#, RegularExpression["[0-9]+"]] & /@ fList]]
{1, 2, 4, 5, 6, 7, 8, 9, 10}
So there are two ways now:
1a Knowing the numbers
If we know that it starts at 1
and ends at 10
with 3
missing, we just do:
Table[If[i != 3, iData[i] = Import["myData" <> IntegerString[i, 10, 5]<> ".txt","Table"]], {i, 10}];
1b Using the file list
If we are not sure about the numbers we use the file list and extract the numbers from the file names:
Table[
newiData[
ToExpression[
StringCases[i, RegularExpression["[0-9]+"]
]
][[1]]
] = Import[i, "Table"], {i, fList}]
Remarks
Now iData[i]
and newiData[i]
should be identical.
Note that especially the second case works if you have file names of the type:
"known name"<>"variational unknown part"<>"unknown length numbers"<>".dat"
ToString
. $\endgroup$(data[#] = Import["restofname-" <> ToString[#], "Table"]) & /@ list
$\endgroup$IntegerString[]
in case you need padding, e.g. name-001.dat $\endgroup$?*String*
can be worth a try. $\endgroup$