|
Answer» So I am trying to copy some log files from a server from multiple numbered folders and only for a certain amount of time. My problem is I can create a batch file that will sort through each folder and copy the SELECTED file, but they are IIS logs that all have the same file name in different folders.
Here is what I currently have: FOR %%A IN (1 3 4 7 8 10 12 15) DO copy \\servername\logs\W3SVC%%A\0804(this is where I want to put my selected range of times) c:\logs
First problem is I don't know how to specify multiple variables if it is possible and secondly the naming conventions are the same across all the log folders so I would need to rename them in the destination folder. Does anyone understand what I am tryin to do?If I understand correctly, (and I may not) You want to copy various files, all with the same name to one local folder. Logic dictates you must rename them, can't have 'em all with the same name. I don't know what file extension you have but lets PRETEND its .txt for the moment. So you have:
FOR %%A IN (1 3 4 7 8 10 12 15) DO ( copy \\servername\logs\W3SVC%%A\Filename.txt c:\logs )
Why not just append the unique directory number to each file? So:
FOR %%A IN (1 3 4 7 8 10 12 15) DO ( copy \\servername\logs\W3SVC%%A\Filename.txt c:\logs\Filename%%A.txt )
I should point out my knowledge of DOS is pretty limited, it just happens that I spent a while TODAY working out how to do a similar thing . That is great input, I actually ran this batch yesterday to gather the data renaming each file with first variable.
What I was really asking about though was the ability to include more than one variable into a batch statement like:
where %%B IN (0803 2049 2123) FOR %%A IN (1 3 4 7 8 10 12 15) DO copy \\servername\logs\W3SVC%%A\0804%%B* c:\logs\%%A.log
If that makes any sense D:So like a nested FOR loop?
FOR %%B IN (0803 2049 2123) DO ( FOR %%A IN (1 3 4 7 8 10 12 15) DO copy \\servername\logs\W3SVC%%A\0804%%B* c:\logs\%%A.log )
So it will run
FOR %%A IN (1 3 4 7 8 10 12 15) DO copy \\servername\logs\W3SVC%%A\0804%%B* c:\logs\%%A.log
3 times with, once with each of 0803, 2049, 2123 as %%BThat worked PERFECTLY! You rock.
|