Announcement

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

  • unzipping multiple files, while naming differently.

    I have multiple zipfiles that i already unzipped but i wanna rename them.

    my first section of the commands worked, but the second part isn't working.

    my files are named as : JobID-82_H4_BHS_2014_Import
    JobID can be one digit, two or three digits, and i want to extract "BHS" part. So i might have to backtrack (from 13 to 15 starting from the end)
    but it's not working..


    local unzipdir "U:\blah"


    local files : dir "`unzipdir'" files "*.dta"
    foreach file of local files {
    local cty_iso = substr("`file'",15,13)
    local fname = "`cty_iso'.dta"
    copy "`unzipdir'/`file'" "`sourcedir'/`fname'", replace
    }
    Last edited by Olivia Johns; 10 Jul 2017, 15:41.

  • #2
    I tried this but nothing, it just says end of do-file but no dta files created

    local files : dir "`unzipdir'" files "*.dta"
    foreach file of local files {
    local cty_iso = substr(reverse("`file'",13,15))
    local fname = "`cty_iso'.dta"
    copy "`unzipdir'/`file'" "`sourcedir'/`fname'", replace
    }

    Comment


    • #3
      Could you please follow the advice in section 12.1 of the FAQ? Please don't say something "doesn't work" and please don't paraphrase Stata output.

      Comment

      Working...
      X