You have a directory full of log files that you want to import into Excel or a database so you can do some processing on them… but there are hundreds of files… how do you make them into a single file?

Answer: Pull out your DOS hat, open a command prompt, and then use the “for” command.

The syntax works something like this:

for <variablename> in (<directorylisting>) do <command> <variablename>

So if you wanted to append all of the *.log files in a directory, you’d use the “type” command and then pipe it into a single file using the >> operator.

The difference between >> and > is that the former appends data to the end of the file, and the latter will completely replace the file, which would be pointless for what we want to do.

So here’s the command you’d run, assuming you are in the directory containing the log files.

for %f in (*.log) do type "%f" >> aggregate.txt

And yes, I actually just used this command for a project at work, which is why I’m writing up this article. =)

Random thought: What on earth would a DOS hat look like?

Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »

The above article may contain affiliate links, which help support How-To Geek.