SYNC - Synchronizes two directory trees

SYNC is a program which updates one directory tree from another. SYNC
checks the timestamp of each file in the source tree against the same
file in the destination tree, and offers to copy the file only if the
source file has the most recent timestamp, or the file does not exist
in the destination directory tree.

SYNC also detects the following special out-of-sync conditions, and
prompts for the action to take:

 - Source file is older than destination.
 - File exists in destination, but not in source.
 - Timestamps are the same but file sizes differ.
 - Directory found in source does not exist in destination.
 - Directory found in destination does not exist in source.

SYNC is very useful to keep two systems synchronized and up to date. For
example, if you work on a desktop system, and routinely use a notebook
system when you are traveling, you can use SYNC before you leave to insure
that your notebook is up to date with your desktop, and again when you
return to insure that your desktop receives all the changes that you
performed while you were on the road.

SYNC is a 16-bit DOS program, however it supports long filenames in an
environment providing LFN support (Win9X/Win2K/WinXp, DOSLFN etc.)

command syntax: SYNC source_path dest_path [options]

 source_path = Newer directory tree
 dest_path   = Directory tree to update

options:

 /1[!]   = ignore/update! timestamp if exactly 1 hour difference
            Does not copy files which are the same size and have a timestamp
            which differs by exactly 1 hour. This is a work-around for a
            windows bug where the timestamp of a file changes by one hour
            when windows adjusts to or from daylight savings time.
            /1! updates the destination timestamp in this case.

 /A      = copy file Attributes
            When a file is copied, the attributes (Archive, Read-only,
            Hidden and System) of the destination file are updated to
            match the the source file.

 /C      = auto-Copy new files
            Automatically copies (without prompting) if the destination file
            is older, or does not exist.

 /D      = auto-create new Directories
            Automatically create subdirectories in the destination tree if
            they do not already exist.

 /E      - continue on Error
            Keeps going even if errors occur in opening individual files.

 /H      - ignore Hidden&system files/dirs
            Files/Directories with the Hidden or System attributes in either
            the source or destination tree are not processed.

 /I      - Ignore time/date, compare size/content only
            SYNC will pass files with different time/datestamps as long as
            their size and content (if /T) match.

 /L      - disable Long-filename support
            Prevents SYNC from using long filenames even if a LFN manager
            is present (Win*, DOSLFN etc.)

 /Q      - Quiet: reduce informational output
            Does not display source & destination paths when recursing
            through the directory tree.

 /R      - auto-override Read-only attribute
            Automatically copies (or deletes) files with the Read-only
            attribute set. Without this option, you will be prompted
            whenever a Read-only file is to be modified.

 /S      - auto-Skip safe copies
            Automatically skip (do not copy) if the dest file is older or does
            not exist. This is useful to test the operation of SYNC without
            actually copying the files, as it will only stop and prompt for
            out-of-sync conditions. This is also useful if you want to create
            an empty copy of a directory tree structure: SYNC source dest /D /S

 /T      - Test content of files
            Test content of files that appear to be identical (same time/date
            and size). This is time consuming, but it is an easy way to be
            sure that the data in two directory trees is absolutely identical.

 /V      - Verbose: display files processed
            Displays the name of each file that is processed.

 /X      - ignore eXtra dirs in dest.
            You will not be prompted to remove directories in the destination
            tree which do not occur in the source tree.

 /Y      - auto-Yes to unsafe operations
            Disable "Are you sure?" prompt for unsafe or out-of-sync
            operations.

 /~      - scan for SFNs in source
            Alerts you to any files in the source tree which only have "Short
            names". This is allow you to detect a condition under which a bug
            in windows can cause loss of data, for example:
            - You have a file called 'mylongfile.dat' which you copy onto
              the windows system using a means which does not preserve the
              LFN - windows now has a file with only the "short name":
              'MYLONG~1.DAT'
            - You subsequently copy a file called 'mylonghaul.dat' to the
              windows system using windows tools - windows now has another
              file with the name 'mylonghaul.dat', and assigns it a "short
              name" of 'MYLONG~2.DAT' (so far so good).
            - You XCOPY the files to a new location, windows happens to copy
              'mylonghaul.dat' firsts, creating 'mylonghaul.dat' and assigns
              at a "short name" of 'MYLONG~1.DAT' (at this point MYLONG~1.DAT
              did not previously exist at the new location), then the original
              'MYLONG~1.DAT' is copied, which overwrites 'mylonghaul.dat'.
            - In the end, you have only one file called 'mylonghaul.dat',
              which contains the data from 'MYLONG~1.DAT' the original data
              from 'mylonghaul.dat' has been lost.
            This can occur any time you have files which have "lost" their
            long filenames due to copying with non-LFN tools, and subsequently
            copy them with LFN aware tools - this is because windows "squirms
            around" the short name numeric assignments when it copies files.

 D=n     - do not create new Directories at top n levels of tree
            Prevents SYNC from creating/copying new directories at the top
            of the directory tree. Examples:
             D=1  - Prevents SYNC from prompting if the destination tree
                    does not exist. Useful to keep batch files from halting.
             D=2  - Prevent prompting at the top level of directories.
                    Useful to SYNC only directories already copied.

 E=file  - specify file of files to Exclude
            Specifies a file of files to exclude (one per line). Entries
            may be either filenames or directory names, and may contain
            wildcards:
                ? - Matches any single character
                * - Matches any string of characters
                . - has no special meaning (must match a '.')
            All paths must be relative to the starting path. NOTE that the
            match is done against the full relative path - so you must use
            a '*' wildcard to deal with preceeding directories, Examples:
                *.tmp       - Exclude any file ending with .tmp
                *\temp\*    - Exclude any file within a 'temp' directory
                tmp*        - Does NOT exclude any files beginning with 'TMP'
                              (excludes top-level dirs beginning with 'TMP')
                *\TMP*      - Excludes any file/dir beginning with 'TMP'
            An extension of .SNC is assumed if none is specified.

Options can be preset in SYNCOPT environment variable.
To disable an option preset in SYNCOPT from the command line, you can follow
it with '-'. Example: if /T has been preset in SYNCOPT, you can perform a
SYNC without /T by specifying: /T-

When SYNC detects differing files, or an out-of-sync condition, it will
prompt you with the available operations. You may enter one of the
following commands:

 A          - Automatically Copy remaining new/safe files in this dir.
 C          - Copy file from source to destination
 K *        - Copy file from destination to source (out-of-sync)
 D *        - Delete file from destination
 E *        - Delete file from source
 S          - Skip this file (do nothing)
 B          - Bypass remainder of this directory and proceed to subdirs
 L          - Leave this directory and all subdirs
 <esc>      - Enter error recovery menu. This offers:
               A - Abort SYNC and terminate
               C - Return to upper command menu
               D - Invoke a DOS shell

Commands marked '*' are considered unsafe, in that they may lose data.
A Copy command in which the destination file is newer than the source is
also considered unsafe. For these conditions, an "Are you sure" prompt
is issued.

NOTE: When prompted to create a destination directory, you may also type
'C' which create the directory, and automatically copy all files and sub-
directories contained within the source.

------------------------------------------------------------------------------
MAR/2011: I have updated SYNC with several new features, including support
for long filenames. I am also including DSYNC.COM, a copy of the original
SYNC that I wrote in 1998. Compared to SYNC.COM, DSYNC.COM :

  - Does NOT support long filenames (DOS 8.3 only).
  - Does not support /A, /E, /H, /L, /R, /~ or D= options described above.
  - Uses '/H' for the 1-hour workaround instead of '/1'.
  - Requires source_path and dest_path to be the first two arguments.
  - Does not recognize "arguments containing spaces".
  - Does not recognize multiple options unless they are separated by spaces.
  - Does not support the SYNCOPT environment variable.
  - Uses a simpler "DOS" file matching algorithm for E=
  - Does not accept 'C' to copy contents when creating a new directory.
  - Does not offer to remove extra directories in the destination tree.
  - Does not offer to override Read-only attributes (copy/delete fails).
  - SYNC.COM can handle a much larger file/directory name list.
  - DSYNC.COM uses only 64k of memory, SYNC.COM uses 256k.

------------------------------------------------------------------------------
AUG 2012: I have added a new "DOSYNC" utility to the package which I use to
simplify keeping large archive drives in sync. SYNCing an entire drive can
be problematic because:
  - SYSTEM directories on the drive may not be SYNCable, eg:
     "RECYCLER", or "System Volume Information"
  - There may be directories on the drive that you do not want to SYNC.
  - If you abort/fail for any reason, you have to reSYNC the whole drive.
  - Very large trees can overflow SYNC's internal buffers.

DOSYNC simply scans for directory names in the current directory, presents
a menu of the directories that it found allowing you to deselect ones that
you don't want, and then runs SYNC on each individual directory.
This resolves the problems mentioned above by:
  - SYSTEM & HIDDEN directories are automatically deselected.
  - You can manually deselect any additional directories that you don't want.
  - You can deselect directories prior to a failure point.
  - SYNC only has to buffer from each root level directory.
DOSYNC has functions to deselect all, before/after the cursor, directory
names containing <=' ' or >='~' characters etc. Press '?' on the main screen
to see the available commands.

To perform SYNC, DOSYNC must know the location of the SYNC.COM command, and
the options to pass to it. You are prompted with these items before the SYNC
commands run. You can change the default values with: DOSYNC /D
NOTE:   If 'Cmd' is empty, DOSYNC looks for SYNC.COM in your PATH.
        'Opt' defaults to: ?"?N?" ?"?D\?N?" /H /R
            ?N = Insert Name of directory
            ?D = Insert destination prefix **
            ?" = Insert '"' only if ?N contains <=' ' or >='~' characters
            ?? = Insert single '?'

** ?D inserts a destination prefix from the DOSYNC command. For example,
if you executed DOSYNC with the command: DOSYNC J:
then '?D' would be replaced by 'J:'.

DOSYNC accepts the following command line options:

/D  = edit Default Cmd/Opt values.
/T  = Test mode - shows SYNC commands, but does not execute them.

------------------------------------------------------------------------------

Dunfield Development Services (DDS) offers software and firmware
development services specializing in systems and embedded applications.
For more information, visit: http://www.dunfield.com
