Solved

Move files using Batch file

Posted on 2007-03-20
1
1,213 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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