Page 1 of 1

FOR loop to redirect 'type' output of multiple subfolders

Posted: 06 Aug 2015 08:28
by jabadm
Hi! I've never been great at getting my own FOR loops work, so I'm here for help!

Here's my goal: Use a batch file to redirect the contents of a log file into a new log file that the batch has created.
e.g.:

Code: Select all

type logfile.log >> batchlog.log


Here's why it's difficult: the current running directory is %windir%\Temp, but the relevant subdirectories are not static in name. They have the a date/time stamped onto a common prefix: e.g. FOLDERNAME-yyyymmdd-HHmmss.log

So, I need to parse through these folders for a file name that is similar in structure: FILENAME-yyyymmdd-HHmmss.log

I'm not necessarily beholden to a FOR loop, nor even a batch file per se, but this is the path I've taken thus far.

Here's what I've got so far (which doesn't seem to work!):

Code: Select all

for /d /r %%X in (C:\Windows\Temp\LOGDIRECTORY-*) do type %%X\LOGNAME* >> \\share\path\BATCHLOG.log 2>&1


Any and all help will be appreciated!

Re: FOR loop to redirect 'type' output of multiple subfolder

Posted: 06 Aug 2015 09:01
by jabadm
Hi!
I think I found the issue: simply too many switches. I removed the /R and all is right in the world!


for /d %%X in (C:\Windows\Temp\LOGDIRECTORY-*) do type %%X\LOGNAME* >> \\share\path\BATCHLOG.log 2>&1


Thanks to anyone who read.