Hello All,
I have multiple folders, each of which I would like to separately loop over and append all files in a given folder. I am trying to make a for loop to loop over all the folders, with a nested for loop that does the appending. Note that the data I am using is confidential so I have just put placeholders for variable and file names. I would like to use the actual folder names to save the appended files.
I am sure there are other errors in this code that I haven't reached yet, but I am having the simplest issue that I do not know how to resolve. My display command in the second line of my first for loop displays the correct path, but when I use
I get an "invalid syntax" error, and I am not entirely sure why.
Also, just as a reference, I have used these other two posts to construct this code:
https://www.statalist.org/forums/for...umber-of-files
https://www.statalist.org/forums/for...path-file-name
I have multiple folders, each of which I would like to separately loop over and append all files in a given folder. I am trying to make a for loop to loop over all the folders, with a nested for loop that does the appending. Note that the data I am using is confidential so I have just put placeholders for variable and file names. I would like to use the actual folder names to save the appended files.
Code:
global input "F:\input\" global output "F:\output\" global temp "F:\temp\" local folder_names `" "Folder_1" "Folder_2" "' foreach folder of local folder_names{ tempfile building di "$input""`folder'" cd "$input""`folder'" local filelist: dir "." files "*.csv" foreach file of local filelist{ append using `building' save "$temp"`"`building'"',replace } use "$temp"`building', clear save "$output""`folder'" }
Code:
cd "$input""`folder'"
Also, just as a reference, I have used these other two posts to construct this code:
https://www.statalist.org/forums/for...umber-of-files
https://www.statalist.org/forums/for...path-file-name
Comment