FOR loop to redirect 'type' output of multiple subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jabadm
Posts: 7
Joined: 14 Oct 2010 10:04

FOR loop to redirect 'type' output of multiple subfolders

#1 Post by jabadm » 06 Aug 2015 08:28

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!

jabadm
Posts: 7
Joined: 14 Oct 2010 10:04

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

#2 Post by jabadm » 06 Aug 2015 09:01

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.

Post Reply