Dear all,

I cannot work out the following problem:

I have an excel spreadsheet called datax with two variables: refid and attachments
-refid is a number that is coded in terms of string, for example "123429058"
-attachments is a string variable. For some refids, attachments can be blank or have a value. An example of value for attachments could be "1-s2.0-S0959804914009988-main.pdf" or "1-s2.0-S0959804914009988-mmc1.doc" or "1-s2.0-S0959804914009988-main.pdf1-s2.0-S0959804914009988-mmc1.doc"

I run the following code that creates a folder for each refid

cd "C:\Users\user\Downloads"

import excel "datax.xlsx", sheet("DistillerSR") firstrow case(lower) clear

levelsof refid, local(id)

foreach x in `id' {
mkdir `x'
}
I have in the directory "C:\Users\user\Downloads" several pdf files, doc files, zip file and image files.

I want to move them from that directory to the specific refid folder I have generated previously.The excel spreadsheet indicates which refid folder I I should move the file. For some refids there is no files to move, for some it is just one file to move and for some there are multiple files to move.

I have tried the following code but it does not work

levelsof refid, local(id)
foreach x in `id' {
levelsof attachments if refid=="`x'", local(p)
copy "`p'" "C:\Users\joaol\Downloads\\`x'\\`p'", replace
}
Please can you help me? it should be a simple thing to do but I cannot work out the problem?


Thank you

Andre