Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate, copy and rename files recursively

Status
Not open for further replies.

Kozimoto

Technical User
Sep 25, 2002
44
0
0
US
Hi everyone,

I have been using xcopy to copy IIS logs to another server for statistical analysis using xcopy g:\Logs\iis\*.log \\destinationserver\logs\iis\*.log_%computername% /D /Y /S. This basically copies all .log files recursively from each site ID directory to the destination server, and adds the server name to the end of the file for identification.

It works ok, but I end up with file names looking like ex090928.log_servername on the destination server. I'd really like it to be ex090928_computername.log

Any help is greatly appreciated.
 
Thx MM. Recursion works fine using xcopy. But there just doesn't seem to be a way to wind up with the file copied and renamed the way I would like it.

Currently: ex090928.log >> copied to another server using the command above and I get ex090928.log_servername

What I would like is ex090928.log >> ex090928_servername.log

A vbscript or powershell script that does it all in one operation. The problem is I'm not a programmer, I've scoured the net, and nothing seems to fill the bill. Thanks again.

 
does this not work

xcopy g:\Logs\iis\*.log \\destinationserver\logs\iis\*%computername%.log /D /Y /S

perhaps you can consider using a folder to hold the machines log files in? this way you get your extraction?

e.g.

xcopy g:\Logs\iis\*.log \\destinationserver\logs\iis\%computername%\*.log /D /Y /S
 
See if this DOS batch file works for you. Remove the echo when/if you are happy its doing what it should be


cd g:\logs\iis
for /R %%i in (*.log) do (set fname1=%%i) & (set fname2=%%~ni) & call :rename
goto :eof
:rename
echo rename %fname1% \\destination\logs\iis\%fname2%_%computername%.log
goto :eof



In order to understand recursion, you must first understand recursion.
 
Here is the script that finally worked correctly. Must be 3 lines in a .bat file exactly as shown:

@echo off
for /f "tokens=*" %%A in ('dir /b /s "g:\logs\iis\*.log"') do echo f| (
xcopy /d /y "%%A" "\\SERVERNAME\%%~PA%%~NA_%computername%%%~XA" > nul)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top