Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting a list of sub directories

    Hello.

    I want to repeat same work in all sub directories.
    How can I obtain a list of sub directories in the working directory?

    Thanks.

  • #2
    The extended macro function dir should do what you want. Here is an example of its usage:

    Code:
    local subdirs : dir "." dirs "*"
    The above tells Stata to store in local macro subdirs a list of all subdirectories within the current directory ("."). The "*" is a wildcard pattern -- if you wanted only directories starting with, say, "a", you would specify "a*" or any other pattern you wished.

    After the above, left in subdirs will be a space-separated list of directories in the order the operating system returned them to Stata. That is, if you wanted them in alphabetical order, you'll need to sort them yourself afterwards. Each directory name is enclosed in double quotes ("").

    Comment

    Working...
    X