Solved

Batch Script to copy and remove files from one directory to another

Posted on 2011-03-21
9
257 Views
Last Modified: 2012-05-11
Need to do the following:

1) Local Disk: C://users/administrator/backup
2) Network Drive: Z//backup/production

Need to run a Batch script which simply Runs daily and COPIES all the files from Local Disk C TO Network drive Z. It also removes all the files from Local Disk C when the files have been copied successfully and Appends the new files to the Network Drive on a daily basis.

thanks.
0
Comment
Question by:timerack
[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
9 Comments
 
LVL 22

Accepted Solution

by:
chakko earned 168 total points
ID: 35180167
how about this:

move C:\users\administrator\backup\*.*  Z:\backup\production\  /Y


/Y is to overwrite is destination folder has a same file already.
0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35180243
Is this a Windows environment?

1) Local Disk: C://users/administrator/backup
2) Network Drive: Z//backup/production

I do not recognize the slashes (/) - would be backslash (\) in Windows.

If this is windows:

Make a short batchfile:

Use xcopy with appropriate flags to copy files and directories
Use del with appropriate flags to delete copied files.

I assume that the files have different names from day to day - otherwise you have to deal with that as well not to lose information by overwriting.

The spec of what you want to achieve has to be more specific!
0
 
LVL 3

Assisted Solution

by:ssisworo
ssisworo earned 166 total points
ID: 35180340
try this.....


-----------------------------------

@echo off

echo ####### Renaming backup for safety
move /y "C:\users\administrator\backup" "C:\users\administrator\backupmove"

echo ####### Create new backup
md "C:\users\administrator\backup"

echo ####### Backup backup
xcopy /s /c /d /e /h /i /r /y "C:\users\administrator\backupmove" "z:\backup\production"

echo ####### Remove backupmove after Backup
RD /s /q "C:\users\administrator\backupmove"

echo ####### Backup and Delete Complete!
@pause


------------------------
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Assisted Solution

by:xylog
xylog earned 166 total points
ID: 35180828
Robocopy can do this in one command:

robocopy C:\users\administrator\backup Z:\backup\production /e /move

You can schedule it with task scheduler or the at command:

at 23:00 /every:M,T,W,Th,F cmd /c robocopy C:\users\administrator\backup Z:\backup\production /e /move

Please note that using a mapped drive in a scheduled task is tricky. You will likely have trouble with the drive letter. A UNC path might work instead but you would need to make sure that the account that is running the task has sufficient privileges to access that share.

For the AT command there is some info here: http://support.microsoft.com/kb/q158825/

Otherwise you can try using the Task Scheduler which allows you to specify an individual user account to use for running your command.

0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35180867
Does Windows server 2003 contain robocopy? SSisworo is anyway correct about his part and XYLOG about scheduling
0
 
LVL 5

Expert Comment

by:xylog
ID: 35182533
Robocopy is a free download here as part of the  Windows Server 2003 Resource Kit Tools -> http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

0
 

Author Comment

by:timerack
ID: 35373574
Thanks everyone for the response. I am reviewing it and will get back to you guys soon.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 35994277
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

734 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