?
Solved

Move files using Batch file

Posted on 2007-03-20
1
Medium Priority
?
1,217 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

801 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