0
$\begingroup$

I want to create several directories "dir_i" in a mother directory "home". and put an specific file in each directory "file_j". so that I will have home/dir_1/file_a, home/dir_2/file_b,...

Table[CreateDirectory["home/dir_i"],{i,1,10}]

obviously doesn't work because "home/dir_i" is a string not an expression.

$\endgroup$
8
$\begingroup$

Try this and check for ToString and StringJoin (<>) in the docs!

Table[CreateDirectory[ToFileName[{"C:","Users", "dir_"<>ToString[i]}]], {i, 1, 4}]

Use ToFileName so the code is platform-independent.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.