1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

delete files not on another drive

Discussion in 'T&T - Scripting' started by mneumann, Feb 14, 2009.

  1. mneumann

    Joined:
    Feb 14, 2009
    Messages:
    4
    Likes Received:
    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.
     
  2. mtotman

    Joined:
    May 29, 2008
    Messages:
    19
    Likes Received:
    0
    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.
     
  3. mneumann

    Joined:
    Feb 14, 2009
    Messages:
    4
    Likes Received:
    0
    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.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,092
    Likes Received:
    85
    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
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,092
    Likes Received:
    85
    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
     
  7. mneumann

    Joined:
    Feb 14, 2009
    Messages:
    4
    Likes Received:
    0
    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
     
  8. mneumann

    Joined:
    Feb 14, 2009
    Messages:
    4
    Likes Received:
    0
    Thanks, but the batch file deleted a bunch of stuff in the SOURCE directory!

    mn
     
  9. Roedy

    Joined:
    Jun 8, 2008
    Messages:
    120
    Likes Received:
    2
    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.
     
  10. Roedy

    Joined:
    Jun 8, 2008
    Messages:
    120
    Likes Received:
    2
    I written similar logic in the form of a Java program called BackupToZip that maintains a mirror copy of a set of directories trees in a ZIP archive file. It updates, adds and deletes as appropriate to keep it in sync.

    You can get a copy free with source from

    http://mindprod.com/products1.html#BACKUPTOZIP
     
  11. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,054
    Likes Received:
    1
    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.....

    ?
     
  12. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    I'm guessing they probably figured it out at some point in the last 7 years since the previous post.
     
  13. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    358
    Likes Received:
    8
    :-)

    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 )
     
    #13 MaartenG, Oct 17, 2016
    Last edited: Oct 17, 2016

Share This Page