I have thousands of city folders (say city1, city2, and so on, but in reality named like 北京, 上海, etc.)
Each folder further contains two subfolders: land and house.
So the directory structure is like
currentdictionary
---- city1
----- house
------ many .xlsx files
----- land
----- city2
----- city3
···
----- city1000
I want to get the complete list of all subdirs and do some manipulation (like import excel). I know there is a macro extended function:
- local list: dir
to handle this issue, but it seems it can only return the first tier of subdirs, like city_i, rather than those deeper ones.
I use the following snippet of codes to test my ideas, if the approach works, it should return a full list of city names and each city's project
set more off
cdG:\Data_backup\Soufang_data
local folder:dir . dirs "*"
foreach i oflocal folder {
di "`i'"
local `i'_house : dir "G:\Data_backup\Soufang_data/`i'\house" files"*.xlsx"
foreach j of local `i'_house {
di "`j'"
}
}
However, the outcome on the screen is something like
city1
project100
project99
······
project1
It seems the code only loops one round, over the first city, but fails to come to city2,city3 and so on. I suspect it's due to my problematic writing of the local,espcially in this line
- foreach j of local `i'_house
but I'm not sure.