Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Move files using Batch file

Posted on 2007-03-20
1
Medium Priority
?
1,219 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 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