Announcement

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

  • Compound Quotes in Macros

    I trying to automate directory change using Macros, I have automate the address generation D:\statawork\2017\abc 123.
    But the problem is to put in a local with the double quotes, because my addresses have spaces, for directory change.
    Here is my complete code and output is below;


    . local folder= "$main\\`curr_year'\CCS-Telephone\\`first_name' CCS"

    . di "`folder'"
    D:\Official\2017\CCS-Telephone\31st wave CCS

    . cd "`folder'"
    unable to change to D:\Official\2017\CCS-Telephone\31st wave CCS
    r(170);

    end of do-file

    r(170);

  • #2
    Use compound double quotes (see -help quotes-). So,

    Code:
     local folder `"$main\\`curr_year'\CCS-Telephone\\`first_name' CCS"'
    di `"`folder'"'
     cd `"`folder'"'


    otherwise, if it's not letting you cd to a folder then it's possible it doesnt exist. You can check for the existence of a folder by using -capture- and -confirm- together before the -cd- command, e.g.,
    Code:
     local folder `"$main\\`curr_year'\CCS-Telephone\\`first_name' CCS"'
    di `"`folder'"'
    cap confirm file `"`folder'"'
    di _rc
    if !_rc cd `"`folder'"'  //only CDs if folder exists!
    Also, the "=" in the local isn't necessary here since you arent evaluating an expression.

    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      Hassan Abbas also keep in mind that people usually don't reply or notice posts in this forum (Sandbox) since it's for testing code - be sure to post in the General forum with questions to get them noticed by the group.
      Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

      Comment

      Working...
      X