Announcement

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

  • importing files and creating a variable recording the size of the fils

    Hello,

    I created a dataset by importing several txt files and now I am wondering if, while importing them, there is a way to create a variable recording the size of the txt.

    Thank you

  • #2
    I will assume you are putting all of these files together by appending them, and that they constitute all of the *.txt files in the current directory. You can modify the code accordingly if you are separately saving them or -merge-ing them or something like that.

    Code:
    clear*
    
    filelist, pattern(*.txt)
    
    capture program drop one_file
    program define one_file
        local dirname = dirname[1]
        local filename = filename[1]
        local fsize = fsize[1]
        import delimited using "`dirname'/`filename'", clear
        gen dirname = `"`dirname'"'
        gen filename = `"`filename'"'
        gen file_size = `fsize'
        exit
    end
    
    runby one_file, by(dirname filename)
    This code requires -filelist- and -runby-, by Robert Picard, and Robert PIcard and me, respectively, both available from SSC.

    Comment


    • #3
      Hi Clyde,

      thank you, the code works perfectly.



      Comment

      Working...
      X