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,...


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


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.


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.