in reply to write multiple files to a new directory

Add "code" tags around your code: Writeup Formatting Tips
below is my code which didn't work
Until you give us more details about how it didn't work, start debugging: Basic debugging checklist