Announcement

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

  • call file with abbreviation

    I have monthly files which names are composed by a standard pattern ("TabelaUnificada_" and respective month/year) followed by a unstandardized pattern (see attachment). I would prefer not to delete the unstandardized pattern from their names once this tells me the exact version of the file I downloaded. There is only one file per month/year.

    I would like to zip all files in a loop. The loop below would only work if I manually delete the unstandardized pattern from the file names.

    Code:
    forval i = 2008/2014  {
    foreach j in 01 02 03 04 05 06 07 08 09 10 11 12  {
    
    zipfile directory TabelaUnificada_`i'`j', saving(TabelaUnificada_`i'`j', replace)
     
    }
    }
    I get this error when I run the code above:
    Code:
    specify at least one file or folder to include in the zip file
    r(198);
    
    end of do-file
    
    r(198);
    Is there a way I could call the files making reference only to the standardized pattern of their name?
    Attached Files

  • #2
    Paula, I think you can do what you want by using the macro extended function -dir- to create a local macro containing the names of each of your subdirectories, and then zip each one. See -help extended_fcn-. Does this do what you want?

    Code:
    cd "Dropbox/Pesquis/.... "  // you need to fill in the entire directory name
    // Obtain list of subdirectories using a sufficiently detailed wildcard specification
    local dirlist: dir "." "TabelaU*"  
    foreach d of local dirlist {
       zipfile directory `d', saving("`d'.zip", replace)
    }

    Comment


    • #3
      hello Mike Lacy many thanks!

      The code you propose gives me the following error:

      Code:
      . local dirlist: dir "." "TabelaU*"  
      invalid syntax
      r(198);
      
      end of do-file
      
      r(198);
      
      .

      Comment


      • #4
        I don't commonly use this extended macro function to get a list of directories, but by looking at the documentation, I'm seeing that it's necessary to indicate that a listing of directories is needed. Take a look at -help extended_fcn-, looking for "Macro extended functions for filenames and file paths."

        It appears that something like this might work:
        Code:
         local dirlist: dir "." dirs "TabelaU*
        "

        Comment

        Working...
        X