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
0 Response to Appending Files in a Folder for Multiple Folders
Post a Comment