File names in a Do Loop: Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter ilvreth
  • Start date Start date
  • Tags Tags
    File Loop Mathematica
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 6K views
ilvreth
Messages
33
Reaction score
0
Does anybody know how i can make files in a do loop in mathematica?

For example i want a do loop as (here is not mathematica language)

Code:
do i=1,10
make file = text_i.txt  (here i is the index of the do loop)
end do

The results of this process would be ten files as
text_1.txt
text_2.txt
text_3.txt
.
.
.
text_10.txt
How this can be written in mathematica?
 
Physics news on Phys.org
In[1]:= For[i=0,i<3,i++,
name="text"<>ToString[i];
Print[name];
]

From In[1]:= text0
From In[1]:= text1
From In[1]:= text2

Underscore "_" has a very special meaning in Mathematica and you almost certainly do not want to do that
 
Do[Put[StringJoin["text_", ToString, ".txt"]], {i, 10}]
will create the 10 empty files in the current Directory[]