foreach path {tmp tmp/tmp1 tmp/tmp2 tmp/tmp3} { file mkdir $path foreach nm {fileA fileB fileC} \ contents [list 12345 12345 $path] { set of [open $path/$nm-[file tail $path] w] puts $of $contents close $of } }