Windows Server 2003
1755763 Members
2824 Online
108838 Solutions
New Discussion юеВ

Re: Execute command on files in a dir using bat script

 
Maxim Vexler
Occasional Contributor

Execute command on files in a dir using bat script

For the following name scheme:

access_log-w(WW)-(YYYY-MM-DD).log

Where
WW = week (2 digits)
YYYY = year (4 digits)
MM = month (2 d)
DD = day (2 d)

The script doesn't have to know what week it is, all it has to do is "dir" the directory, select the files that match this scheme and the execute a command with the file found (the log file as an argument.

Any pointers (or the whole script for that matter) would be mostly appreciated.

Thank you,
Maxim.
2 REPLIES 2
Wijnand Lammens
Advisor

Re: Execute command on files in a dir using bat script

Maxim,

I'm not sure what you mean with "match the scheme", but might this be helpful?

for /f %%a in (
'dir /b "access_log-w(??)-(????-??-??).log"'
) do (
echo %%a
)

Just replace "echo" by your command.

Regards,
Wijnand
Maxim Vexler
Occasional Contributor

Re: Execute command on files in a dir using bat script

Thank you.

I must have misused the term "scheme".

Your answer is exactly what I had in mind.