Compare to directories and delete...

Microsoft Windows xp professional w/serv...
December 16, 2009 at 07:13:59
Specs: Windows XP
Hello all,

I hope someone out there will be able to help as this is driving me mad!

I have the script below which copies files from my C: drive (Laptop) onto E: (External Hardrive).

So far this works great, however I want to delete files from the External Harddrive if they no-longer exist in the location on C:\.

I realise I could delete everything on E: before starting the copy but it seems to be a waste when only a few files are being deleted (or moved) each time I backup.

------------------------------------------------------------------
mode con:cols=55 lines=15
@echo off

:START
IF NOT EXIST E:\TEST\ GOTO END
GOTO BACKUP

:BACKUP
set file1=%date:~-4,4%%date:~-7,2%%date:~-10,2%-%time:~0,2%%time:~3,2%.txt
echo File Synchronisation on %date% at %time% >> "E:\TEST\Backup Logs\Laptop-to-Network\%file1%"
echo ---------------------------------------------------- >> "E:\TEST\Backup Logs\Laptop-to-Network\%file1%"
xcopy /E /D /Y /I "C:\TEST" "E:\TEST" >> "E:\TEST\Backup Logs\Laptop-to-Network\%file1%"
GOTO FINISH

:END
echo. The Network path is not available
PAUSE

:FINISH
------------------------------------------------------------------

Any help would be greatly appreciated.

Thanks,

Greg


See More: Compare to directories and delete...

Report •


#1
December 16, 2009 at 07:21:42
There's fully thought out functions for that :

XXCOPY /CLONE

or

ROBOCOPY /MIR

(MIR relates to MIRroring)


Report •

#2
December 16, 2009 at 07:26:05
Both are not recognized as an internal or external command?

Report •

#3
December 16, 2009 at 07:40:33
That's correct, but none of the standard tools have got a real cloning feature. The "XCOPY /D" comes close, but the actual cleanup of directories, the thing you are asking for, is just what is missing there.

Robocopy is supported my MS, don't worry.
XXCOPY is non-MS freeware


Report •

Related Solutions

#4
December 16, 2009 at 07:45:12
Hi tvc,

So, as I can't use xxcopy or robocopy either does that mean I'm stuck?

Greg


Report •

#5
December 16, 2009 at 08:19:59
I don't know why it would be a hardship to do a mass delete. But..


not tested

==============================
@echo off > newfile & setLocal enableDELAYedexpansion

pushd c:\

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d e:\') do (
if not exist "%%~Na%%~Xa" del "%%a"
)


=====================================
Helping others achieve escape felicity

M2


Report •

#6
December 16, 2009 at 08:33:04
Hi Mechanix2Go

Thanks for replying,

I've made the following changes but it's just deleting the files I have in E:\Test even though they exist in C:\Test

==============================
@echo off > C:\newfile.txt & setLocal enableDELAYedexpansion

pushd C:\Test

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d E:\Test') do (
if not exist "%%~Na%%~Xa" del "%%a"
)


Report •

#7
December 16, 2009 at 08:38:44
It looks like your changes are legit.

At the prompt do:

pushd c:\test
pushd e:\test
popd
popd

To see if there's any funny business in the paths.


=====================================
Helping others achieve escape felicity

M2


Report •

#8
December 16, 2009 at 08:44:25
I don't get any prompt. When I run the bat file the window opens, closes about 3 secs later and when I check the E:\TEST location, files have been deleted (but not the folders and sub folders).

Any ideas?


Report •

#9
December 16, 2009 at 09:07:10
"don't get any prompt"

LOL pay attention

start - run - cmd


=====================================
Helping others achieve escape felicity

M2


Report •

#10
December 16, 2009 at 09:11:42
No change.

I still don't get any prompt and it still deletes all the files in E:\TEST


Report •

#11
December 16, 2009 at 09:48:15
Mechanix, I thought it would be diffucult .. maybe it isn't. But still, threadstarter did not manage to do a clean delete (folders and files).

;)

Anyway, threadstarter : you can find robocopy or xxcopy on the internet. Robocopy is an MS extension.


Report •

#12
December 16, 2009 at 09:53:12
Does the DEL command work for directories ?

Report •

#13
December 17, 2009 at 05:37:31
Hi all,

Yes the DEL command does work.

It looks like I'll have to use something like Robocopy or xxcopy instead.

Thanks for you help...

Greg


Report •

#14
December 17, 2009 at 05:44:07
If you can't go to a prompt and type in a few chars, there ain't much hope.


=====================================
Helping others achieve escape felicity

M2


Report •

#15
December 17, 2009 at 05:47:29
Thanks. You've been really helpful

Report •

#16
December 17, 2009 at 09:04:42
Yes, but DEL will not remove directories, so you'll need to combine using DEL and RMDIR, otherwise the scripted version would not work.

C:\>mkdir test

C:\>del test
C:\test\*, Are you sure (Y/N)? y

C:\>cd test

C:\test>cd ..

C:\>rmdir test

C:\>cd test
The system cannot find the path specified.

C:\>


Report •

#17
December 17, 2009 at 10:14:26
If you're going to RD, not much point in doing DEL.

==============================
C:\temp\-\d10\gtest\tok\y>md zz

C:\temp\-\d10\gtest\tok\y>rd /s /q zz

C:\temp\-\d10\gtest\tok\y>cd zz
The system cannot find the path specified.
===============================
Which has nothing to do with the issue at hand.


=====================================
Helping others achieve escape felicity

M2


Report •

#18
December 17, 2009 at 12:59:51
You need DEL for the files, RD for the directories. Keep in mind you would not want to delete ONLY files or ONLY directories. In the set of "things" to delete, there will be files and directories.

Unix has got 1 command for deleting files and directories, but Windows hasn't.

Mechanix : response #5


Report •


Ask Question