Solved

File Copy Script

Posted on 2011-03-09
11
383 Views
Last Modified: 2012-06-21
I had a question posted earlier about script to copy files and create a text document of the files that were copied:
I need a script to create a folder on a Log Server and then copy files from one Server into that folder. I need it to create a .txt file listing all the files copied but save that file in a different location. Here is the script I'm using now, so if we can just make additions to this it would be great!!!

@echo off
set T=%time:~0,5%
set dir=%date:/=-% %T::=-%
echo The target folder is "%dir%".
xcopy /s /c /y "D:\GCTI\Logs\KSC_SIP_Agent_1_Bac\Archive\*.*" "\\usmoksc5app55\logs\usmoksc5app10\%dir%\"

The answer was to add to the existing script:
 >> "\\mysharedlocation\mylog.log"

I need a way to make the log file created named for date and time as I will run this script 4 times daily and need to not overwrite any previous logs.

The working answer was to add to the script:
0
Comment
Question by:charlespliler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 2

Expert Comment

by:cefranklin
ID: 35086955
Set an xcopy before to ouput the log file?

@echo off
set T=%time:~0,5%
set dir=%date:/=-% %T::=-%
echo The target folder is "%dir%".
xcopy /L "D:\GCTI\Logs\KSC_SIP_Agent_1_Bac\Archive\*.*" "\\usmoksc5app55"\\usmoksc5app55\logs\usmoksc5app10\%dir%\COPYLOG_%dir%.txt" 
xcopy /s /c /y "D:\GCTI\Logs\KSC_SIP_Agent_1_Bac\Archive\*.*" "\\usmoksc5app55\logs\usmoksc5app10\%dir%\" 

Open in new window

0
 

Author Comment

by:charlespliler
ID: 35087020
I just need the output log file to be named according to date and time it is created instead of log.log as file name, I need 3/9/11 13:20.log
0
 
LVL 2

Expert Comment

by:cefranklin
ID: 35087207
First off, you cannot use a "/" or ":" in file or folder names...
Second, use the %date:/=-% for the date and the %T::=%

%date:/=-% %T::=%.log

Also, I had an error in the line for your script:

xcopy /L "D:\GCTI\Logs\KSC_SIP_Agent_1_Bac\Archive\*.*" > "\\usmoksc5app55"\\usmoksc5app55\logs\usmoksc5app10\%dir%\%date:/=-% %T::=%.log"
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 

Author Comment

by:charlespliler
ID: 35087480
Here is the script with the correct folder names etc, with the additions you gave me. I get a "network Path not Found error for the log creation but the file copy works just like it used to. Ideas???

@echo off
set T=%time:~0,5%
set dir=%date:/=-% %T::=-%
echo The target folder is "%dir%".
xcopy /L "D:\GCTI\Logs\*.*" >  "\\usmoksc5app55"\\usmoksc5app55\logs\usmoksc5app20\%dir%\%date:/=-% %T::=%.log"
 
xcopy /s /c /y "D:\GCTI\Logs\*.*" "\\usmoksc5app55\logs\usmoksc5app20\%dir%\"
0
 
LVL 2

Expert Comment

by:cefranklin
ID: 35087518
Your script is wrong... you have "\\usmoksc5app55 twice
0
 
LVL 2

Expert Comment

by:cefranklin
ID: 35087524
xcopy /L "D:\GCTI\Logs\*.*" >  "\\usmoksc5app55"\\usmoksc5app55\logs\usmoksc5app20\%dir%\%date:/=-% %T::=%.log"

should be

xcopy /L "D:\GCTI\Logs\*.*" >  "\\usmoksc5app55\logs\usmoksc5app20\%dir%\%date:/=-% %T::=%.log"
0
 

Author Comment

by:charlespliler
ID: 35087833
I copied it exactly as you posted but it says: The system can not find the path specified
0
 
LVL 2

Accepted Solution

by:
cefranklin earned 250 total points
ID: 35087876
Uhh, are you making the dir first?  I think the xcopy /s /c /y actually makes the dir but, the /L doesn't?

Try adding mkdir "\\usmoksc5app55\logs\usmoksc5app20\%dir%" before the xcopy /L

0
 

Author Closing Comment

by:charlespliler
ID: 35088024
That was it, no Directory to create the .log in. Thank you so much!!!!
0
 
LVL 2

Expert Comment

by:cefranklin
ID: 35088049
Glad I could help.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 35088229
You might want to put an "IF NOT EXIST" in front of the "MKDIR ..." for safety reasons. That way if it does exist it won't try to create it but if it doesn't then it will.

IF NOT EXIST "\\usmoksc5app55\logs\usmoksc5app20\%dir%" MKDIR "\\usmoksc5app55\logs\usmoksc5app20\%dir%"

Just an afterthought.

:)
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question