Stone Steps Inc.

Article ID: Q20040923-01

Q:Can I process all log files in a directory with a single command?

A:Yes, running the following command in the Command Prompt window will process all log files with the extension .log located in the logfiles subdirectory of the current directory and save all generated reports in the reports subdirectory of the current directory.

> for /F %f in ('dir /O:N /B logfiles\*.log') do webalizer -p -F iis -n -o reports logfiles\%f

The command assumes that webalizer.exe is located in one of the directories in the system path. If you would like to use this command in a batch file, replace %f with %%f.

Note that the dir command, as it shown in the example, will sort log files by name, which will work properly with log files named using year-month-day convention (e.g. ex041014.log). Use the /O:D option instead of /O:N if you would like to sort files by date instead. 

The equivalent Linux command is shown below. The ls command in the example will sort files alphabetically by name. Use the -tr option if you would like to sort log files by time in the ascending order.

$ for obj in $(ls logfiles/*.log); do webalizer -p -F apache -n -o reports $obj; done