2

I have set of files in the format 20160615-1-0.asc, 20160615-2-0.asc,... 20160615-5-0.asc etc. The following commands can List the file names at once which can be used to import later.

  files = Range[1, 5]; 
  c = "D:\\20160615\\20160615-" <> ToString[#] <> "-0.asc" & /@files

I want to use "0" part of the "-0.asc" string as a variable so that I can make different lists of multiple files like {-1-0.asc, -2-0.asc, ...-5-0.asc}, {-1-1.asc, -2-1.asc, ...-5-1.asc},{-1-3.asc, -2-3.asc, ...-5-3.asc}..and so on.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
surjendu
  • 45
  • 3

2 Answers2

4

It seems that a simple modification of your code will work.

fileList[prefix_String, m_Integer, n_Integer] :=
  With[{dash = "-"}, 
    prefix <> dash <> ToString[#] <> dash <> ToString[n] <> ".asc"] & /@ Range[m]

Then

fileList["D:\\20160615\\20160615", 5, 1]

gives

{"D:\\20160615\\20160615-1-1.asc", "D:\\20160615\\20160615-2-1.asc", "D:\\20160615\\20160615-3-1.asc", "D:\\20160615\\20160615-4-1.asc", "D:\\20160615\\20160615-5-1.asc"}

gwr
  • 13,452
  • 2
  • 47
  • 78
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
2

a good use for the "new in 10" StringTemplate :

 Table[
    StringTemplate["D:\\20160615\\20160615-`1`-`2`.asc"][i, j], {i, 3}, {j, 3}]

enter image description here

incedentally, if you need to zero pad your numbers as they often occur in file names you can use this mess:

Table[
 StringTemplate[
   "D:\\20160615\\20160615-<*TemplateExpression[IntegerString[`1`,10,2]]*>-`2`.asc"
    ][i, j], {i, 3}, {j, 3}]

enter image description here

george2079
  • 38,913
  • 1
  • 43
  • 110