Announcement

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

  • Extracting file names with dir and storing them into a local

    Dear statalisters,

    I would like to extract all the sub directory names present in the parent directory and store these names into a local.

    I've been seeking for advice on forums and found the following command that I tried to adapt

    Code:
    local f_names: dir "C:/A/Parent/" files "*" // as these are directories and not *.txt or *.dta
    
    display "`f_names'"
    
    *However nothing is returned
    But nothing goes out

    The purpose would be to use all the elements from `f_names' and then extract the names of text files within each file of f_names directories. I'm planning to do something like

    Code:
    foreach fn of local f_names{
       local txt_files: dir "C:/A/Parent/`fn'" files "*.txt"
    }
    Thank you for your kind help

    Dusan

    (Stata 14.1)

  • #2

    Code:
     local f_names: dir "C:/A/Parent/" dirs "*"  // dirs instead of files for directories.
    Didn't see it immediately in the help

    Comment


    • #3
      For some reason the related help file is called "help extended_fcn". That said, I'm not sure why your code doesn't work. Or does it work now you replaced files with dirs?

      Comment


      • #4
        Hi Jesse, it works now!
        Thanks
        Dusan

        Comment

        Working...
        X