jbla9028
asked on
script to move files
Can someone help provide a script to copy a file to a fileshare and rename a file to
filename_%Serverhostname%_ date.log
This is a windows system.
Thanks!
filename_%Serverhostname%_
This is a windows system.
Thanks!
ASKER
the file name is called resetstats.log no preference on date format. if it could include a time in case I need to copy the file multiple times a day it would be good.
when I do the echo %date% the output is Tue 09/11/2012.
if I type hostname at the command prompt. the server name is displayed which is what I would like in the file name as I'll want to run this on multiple machines and copy it to the same directory.
Thanks for your help.
when I do the echo %date% the output is Tue 09/11/2012.
if I type hostname at the command prompt. the server name is displayed which is what I would like in the file name as I'll want to run this on multiple machines and copy it to the same directory.
Thanks for your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob,
Thank you this works perfectly. The last piece is in the script, where do I specify the UNC path to copy the file to? thanks!
Thank you this works perfectly. The last piece is in the script, where do I specify the UNC path to copy the file to? thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
billprew, this code works but could we add in the time as well? I just get the date. the file copied name was this
resetstats_CRN-JBLA_201209 12.log
resetstats_CRN-JBLA_201209
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
one last thing in that script that's missing in the file output is the server hostname. How can I get that in the filename?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! Here's the final script that worked with the edit provided! Saved the text as a .bat file and viola. Thanks everyone for their help.
@echo off
REM Define where the file comes from, and goes to
set BaseFile=C:\Program Files (x86)\Suite\resetstats.log
set DestDir=\\int\logs\
set DestName=resetstats
set DestExt=log
REM Get the current date/time in YYYYMMDD_hhmmss format
ECHO Date=[%DATE%]
ECHO Time=[%TIME%]
set Stamp=%DATE:~-4%%DATE:~-10 ,2%%DATE:~ -7,2%_%TIM E:~0,2%%TI ME:~3,2%%T IME:~6,2%
ECHO Stamp=[%STAMP%]
REM Copy the file to the server adding the date/time stamp and computer name
ECHO copy "%BaseFile%" "%DestDir%\%DestName%_%COM PUTERNAME% _%Stamp%.% DestExt%"
copy "%BaseFile%" "%DestDir%\%DestName%_%COM PUTERNAME% _%Stamp%.% DestExt%"
@echo off
REM Define where the file comes from, and goes to
set BaseFile=C:\Program Files (x86)\Suite\resetstats.log
set DestDir=\\int\logs\
set DestName=resetstats
set DestExt=log
REM Get the current date/time in YYYYMMDD_hhmmss format
ECHO Date=[%DATE%]
ECHO Time=[%TIME%]
set Stamp=%DATE:~-4%%DATE:~-10
ECHO Stamp=[%STAMP%]
REM Copy the file to the server adding the date/time stamp and computer name
ECHO copy "%BaseFile%" "%DestDir%\%DestName%_%COM
copy "%BaseFile%" "%DestDir%\%DestName%_%COM
Great, glad that helped, thanks for the feedback.
~bp
~bp
Hi, sorry for not getting back to you ....I was asleep ;-)
Just for the sake of completeness, here's the VBS version of the same thing.
Regards,
Rob.
Just for the sake of completeness, here's the VBS version of the same thing.
Regards,
Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
strDate = Year(Now) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Time), 2) & Right("0" & Minute(Time), 2) & Right("0" & Second(Time), 2)
strSourceFile = "C:\Program Files (x86)\Suite\resetstats.log"
strDestinationFolder = "\\int\logs\"
If Right(strDestinationFolder, 1) <> "\" Then strDestinationFolder = strDestinationFolder & "\"
strFileName = Mid(strSourceFile, InStrRev(strSourceFile, "\") + 1)
strDestinationFile = strDestinationDir & Left(strFileName, Len(strFileName) - 4) & "_" & objNetwork.ComputerName & "_" & strDate & Right(strFileName, 4)
If objFSO.FileExists(strDestinationFile) = True Then objFSO.DeleteFile strDestinationFile
objFSO.MoveFile strSourceFile, strDestinationFile
Is %sytemhostname% defined on the computer?
What format do you want the date in?
If you type the following at a command prompt what does it display, exactly?
ECHO %DATE%
~bp