0
votes

I'm attempting to import data from a number of log files. Here's how I'm approaching it:

I have the log files in a separate directory and I generate a txt file with the list of filenames in that directory. I then read through that txt file and subsequently use the filenames in a loop with an import command to bring the data in. This process worked when I last run the do file about 6 months ago and now it's not working.

The basics of the code look like this:

cd "filepath\logs\"
! dir cpuusage*.log /a-d /b /o:-d >"filepath\filelist.txt"

file open myfile using "filepath\filelist.txt",read
file read myfile line

import delimited using `line', delim(" ") varnames(nonames)

The result of that import command is (0 vars, 0 obs) despite the fact that filelist.txt has a list of 14 filenames.

I'm a novice so I'm really hoping there's something simple and obvious that I'm overlooking. I still don't understand why this exact method worked six months ago... Any thoughts?

1
Do your filenames in filelist.txt have embedded spaces? If so, your import delimited command needs to add quotation marks thusly "`line'". - user4690969
The implication of this is the import command was accepted as legal but thinks it found an empty file. It's hard to understand that without seeing your files. Try typing the file using type just before you try to import. - Nick Cox

1 Answers

0
votes

I think you can use fs for this:

cd "filepath\logs\"
fs cpuusage*.log
foreach f in `r(files)' {
    import delimited using `f', delim(" ") varnames(nonames)
}

It's hard to help more without knowing what your log files look like. I would suggest trying to import one using the menu to get the syntax right.