Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

delete files not on another drive

Feb
4
0
I have tried for some time, without much success, to do a btm file which will delete all files on Drive 2 that are not on Drive 1. (I'm using 4NT.) I don't need to check for anything but file-names. Any help with this much appreciated.
 
I have tried for some time, without much success, to do a btm file which will delete all files on Drive 2 that are not on Drive 1. (I'm using 4NT.)

Code:
SYNC /W
should work, if you have a new enough version of 4NT. I'm can't remember when it was added, and it's not in the LE version of TCC.
 
Code:
SYNC /W
should work, if you have a new enough version of 4NT. I'm can't remember when it was added, and it's not in the LE version of TCC.

Thanks - as I understand it, SYNC /W will copy newer files from dir2 to dir1, and therefore from the destination drive to the source drive. Though that's usually no problem, I want an absolutely 1-way process from drive 1 to drive 2. On rare occasion I'll have a newer version of a file on the backup drive that I want to get rid of, not bring onto the source drive.
 
> ---Quote (Originally by mtotman)---
> Code:
> ---------
> SYNC /W
> ---------
> should work, if you have a new enough version of 4NT. I'm can't remember
> when it was added, and it's not in the LE version of TCC.
> ---End Quote---
> Thanks - as I understand it, SYNC /W will copy newer files from dir2 to
> dir1, and therefore from the destination drive to the source drive.
> Though that's usually no problem, I want an absolutely 1-way process from
> drive 1 to drive 2. On rare occasion I'll have a newer version of a file
> on the backup drive that I want to get rid of, not bring onto the source
> drive.

Then why not just delete the contents of the directory on drive 2 & then
copy the directory on drive 1 to the directory on drive 2?

Rex Conn
JP Software
 
rconn wrote:
| ---Quote---
|| ---Quote (Originally by mtotman)---
|| Code:
|| ---------
|| SYNC /W
|| ---------
|| should work, if you have a new enough version of 4NT. I'm can't
|| remember when it was added, and it's not in the LE version of TCC.
|| ---End Quote---
|| Thanks - as I understand it, SYNC /W will copy newer files from dir2
|| to dir1, and therefore from the destination drive to the source
|| drive. Though that's usually no problem, I want an absolutely 1-way
|| process from drive 1 to drive 2. On rare occasion I'll have a
|| newer version of a file on the backup drive that I want to get rid
|| of, not bring onto the source drive.
| ---End Quote---
| Then why not just delete the contents of the directory on drive 2 &
| then
| copy the directory on drive 1 to the directory on drive 2?

What if you have 40GB of identical data already duplicated on both drives?
You'd not want to delete and copy again all of that...

Here is a simple _U_N_T_E_S_T_E_D_ batch program to eliminate all files on
drive 2 which do not
exist on drive 1:

REM P1 is the full path on drive 1 of the top-level source directory
REM P2 is the full path on drive 2 of the top-level target directory

cdd "%P1"
global/i/n gosub DIRTEST
quit

:DIRTEST
set d1=%@replace[%P2,%P1,%_cwds]
do f2 in *
if not isfile "%d1\%f2" del "%f2"
enddo

--
HTH, Steve
 
> | Then why not just delete the contents of the directory on drive 2 &
> | then
> | copy the directory on drive 1 to the directory on drive 2?
>
> What if you have 40GB of identical data already duplicated on both drives?
> You'd not want to delete and copy again all of that...

There's not a lot of difference timewise in having to check the date, time,
and size of the files versus just copying them regardless.

(And if the OP is trying to sync 40GB every day, he should probably rethink
the entire process ...)

Rex Conn
JP Software
 
There's not a lot of difference timewise in having to check the date, time,
and size of the files versus just copying them regardless.

(And if the OP is trying to sync 40GB every day, he should probably rethink
the entire process ...)

Rex Conn
JP Software

Clearly that depends on the file sizes. If it's media files, the check takes far longer than the copying. And with the check, it's not at all inefficient to update 40G of files, even many times a day. The deletion process - which normally involves no more than a dozen files or so - shouldn't add much time, especially since (after copy /u) only a filename check is needed, not a date/time check or CRC.

As for the batch file, I should try it - I have so many backups; it's not much danger....

thanks,

mn
 
I have tried for some time, without much success, to do a btm file which will delete all files on Drive 2 that are not on Drive 1. (I'm using 4NT.) I don't need to check for anything but file-names. Any help with this much appreciated.

Here is a script I use to prune files I back up to my O: flash drive. I think it is very close to what you need:

rem prune the O:\dl directory of files no longer in G:\dl directory tree

set source=G:\dl
set dest=O:\dl


rem delete files in dest that no longer exist on source

O:
cdd "%dest"

rem operate on each dir/file in dest. Delete any file in dest that no longer exists in source
rem Use @replace to modify dest sub dir to equivalent sourcedir
rem Note the explicit cd to set to the found directory. 4NT does not do that for you.


for /a:d /h /r %destdir in (*.*) do ( set sourcedir=%@replace[%dest,%source,%destdir ] & cd %destdir & for /a:-d %destfile in (*.*) do if not ISFILE "%sourcedir/%destfile" del "%destfile" )
rem -30-

This is supposed to be on one long line. I have never been comfortable with the syntax where () span lines. This runs way way faster than copying all the files from scratch.
 
rconn wrote:

[...]

Here is a simple _U_N_T_E_S_T_E_D_ batch program to eliminate all files on
drive 2 which do not
exist on drive 1:

REM P1 is the full path on drive 1 of the top-level source directory
REM P2 is the full path on drive 2 of the top-level target directory

cdd "%P1"
global/i/n gosub DIRTEST
quit

:DIRTEST
set d1=%@replace[%P2,%P1,%_cwds]
do f2 in *
if not isfile "%d1\%f2" del "%f2"
enddo

--
HTH, Steve

How about a nice BTM that would be called and checked for params

C:> remdups.btm "%userprofile%\desktop\charles desktop\" -d "%userprofile%\desktop\Outdrive\" -fm *.*

param[1] = full path to root folder to test, must end in "\"
param[2] = also must end in "\"
-d = delete files from the next param - which must be a full path
-fm = optional semicolon seperated list of file masks to check dir1 and dir2 against...

needs to check for case-sensitive name match, date/time to the minute match, then CRC32 or similar......

only handles two full paths at a time..... so if you have 1 home path and 3 other paths - you'd run it 3 times.....

?
 
How about a nice BTM that would be called and checked for params
I'm guessing they probably figured it out at some point in the last 7 years since the previous post.
 
:-)

This has to be Take Command's version of Fermat's Last Theorem [title] That took ages to get solved (literally) :-)
As there were considerable prizes awarded to solve that one, here's my contribution ;-)

Code:
set DRIVE2=d:\backup
set DRIVE1=C:\temp

dir /esb /a:-d /Nj "%DRIVE2%" | for %FILE in (@CON:) DO if not exist "%@replace[%@UPPER[%DRIVE2%],%DRIVE1%,%FILE]" del /n /a: /f /y " %FILE%"

( @replace is case sensitive, so dir /E and @upper were used )
 
Last edited:
Back
Top