Solved

Move files using Batch file

Posted on 2007-03-20
1
1,215 Views
Last Modified: 2009-12-16
I am using the following batch file to copy files from one location to another:
-----------------

:: @echo off
:: variables
set drive=Y:\
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

Echo ####################################################

echo ### Backing up My Photo...
%backupcmd% "E:\Private" "%drive%\Pictures"
%backupcmd% "D:\My Documents\AutoCAD" "%drive%\AutoCAD"
%backupcmd% "D:\My Documents\Personal" "%drive%\Personal"
%backupcmd% "E:\My Music" "%drive%\My Music"
rem %backupcmd% "E:\6robVideo" "%drive%\6robVideo"
%backupcmd% "E:\Quran1" "%drive%\Quran1"
echo Photo Backup Complete!
@pause
---------------------

My question is how can I modify it so it delete the original files only after a successful copy
Thanks
0
Comment
Question by:Salehd
[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
1 Comment
 
LVL 30

Accepted Solution

by:
SteveGTR earned 125 total points
ID: 18756524
Try this:

@echo off
REM variables
set drive=Y:\
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

Echo ####################################################

echo ### Backing up My Photo...
set Errors=

call :DOBACKUP "E:\Private" "%drive%\Pictures"
call :DOBACKUP "D:\My Documents\AutoCAD" "%drive%\AutoCAD"
call :DOBACKUP "D:\My Documents\Personal" "%drive%\Personal"
call :DOBACKUP "E:\My Music" "%drive%\My Music"
rem call :DOBACKUP "E:\6robVideo" "%drive%\6robVideo"
call :DOBACKUP "E:\Quran1" "%drive%\Quran1"

if "%Errors%"=="Y" echo Errors detected&goto :EOF

del "E:\Private" 2>NUL
del "D:\My Documents\AutoCAD" 2>NUL
del "D:\My Documents\Personal" 2>NUL
del "E:\My Music" 2>NUL
rem del "E:\6robVideo" 2>NUL
del "E:\Quran1" 2>NUL

echo Photo Backup Complete!
@pause

goto:EOF

:DOBACKUP

REM ERRORLEVEL value from: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
REM 0 - Files were copied without error.
REM 1 - No files were found to copy.
REM 2 - The user pressed CTRL+C to terminate xcopy.
REM 4 - Initialization error occurred. There is not enough memory or disk space, or you entered an
REM invalid drive name or invalid syntax on the command line.
REM 5 - Disk write error occurred.

%backupcmd% "%~1" "%~2"
if ERRORLEVEL 2 set Errors=Y

Good Luck,
Steve
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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