Solved

Move files using Batch file

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now