I am constructing a list for use in file operations. Say I want to create list
which contains values from 01 to 87. The kicker is that the first nine integers need to keep a value of 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11.. etc.
So if I create list=Range[87]
I generate a list of integers. Whenever I'm trying to then replace values with '01', etc. they become strings. If they are integers, they revert back to the single value. Ideally, I need a list that I can feed through Do[]
.
Is there a quick way to create a list that uses the two digit form the whole time?
FWIW, the specific application of this that I have a list of files i.e. {1997-01-page100.jpeg, 1997-01-page101,jpeg, <<33 379>>, 1997-87-page9.jpeg, 1997-87-page10,jpeg}
. I'm using the following command to generate specific lists of the sub-file using importlist=FileNames["1997-"<>ToString[x]<>"-*.jpeg"]
but am being thrown off by the zero in front of the single-digit file number.
Answer
I always use IntegerString
for this (I also number my files in a similar way):
In[1]:= IntegerString[#, 10, 2] & /@ Range[87]
Out[1]= {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", \
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", \
"22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", \
"33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", \
"44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", \
"55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", \
"66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", \
"77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87"}
I think this is the most convenient solution, as it's built-in and doesn't require any additional effort to get it working.
Comments
Post a Comment