Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

batch prog to only copy files that do NOT exist in destination

3,498 views
Skip to first unread message

Dave

unread,
Jan 15, 2004, 1:48:03 AM1/15/04
to
Hi all,

Have a simple need to copy files from one folder to another (in W2K) that do
NOT exist
in the destination in a batch file using xcopy. The /U switch for xcopy
only copies over files
that already exist in the destination folder, but there is no switch to do
the opposite.
I figure an advanced batch program could do this, but I have no idea where
to start.

Basically, it would look in the destination folder, if the file in the
destination folder has the same name, but earlier
date, it would overwrite the file. If the destination file is the same, it
does not do an overwrite.
The reason why I need this is that there are several multi-gigabyte files
and copying over the same file is
a huge waste of network bandwidth (not to mention it slows the machine to a
crawl as well).
A single 4GB file is created every so often to the source folder (from
another program) and needs a copy to be sent to the destination folder, but
the file name is different every time, so there is no way to just copy that
file over automatically with a task scheduler - currently, the entire folder
(*.*) is copied over at regular intervals but it unneccessarily overwrites
all the files at the destination folder even if they already exist.

Basically this is the equivalent of a "no to all" button while copying files
in Windows explorer (GUI) - a feature that has been missing from Windows
since the beginning. (currently, one would have to click the "no" button a
zillion times to not overwrite a existing files).

TIA!

Dave


foxidrive

unread,
Jan 15, 2004, 2:06:26 AM1/15/04
to
On Thu, 15 Jan 2004 06:48:03 GMT, Davedelete_this wrote:

> Have a simple need to copy files from one folder to another (in W2K)
>

> Basically, it would look in the destination folder, if the file in the
> destination folder has the same name, but earlier
> date, it would overwrite the file. If the destination file is the same, it
> does not do an overwrite.

I think the /D switch in xcopy would serve that purpose, or you could look
at XXcopy from http://www.xxcopy.com which can maintain mirror backups by
only copying necessary files.

Pegasus (MVP)

unread,
Jan 15, 2004, 2:10:20 AM1/15/04
to

"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> wrote in message
news:DIqNb.54883$Rc4.210599@attbi_s54...

You could try this:

@echo off
set source=c:\My Documents
set dest=d:\My Backup

cd /d "%source%"
for %%a in (*.*) do if not exist "%dest%\%%a" copy "%%a" "%dest%"

A simpler and often far more useful way would be to do this:

@echo off
set source=c:\My Documents
set dest=d:\My Backup

xcopy /d /s /y /c "%source%\*.*" "%dest%\"

Lastly, the public domain program xxcopy.exe is likely to have
a switch to do exactly what you want.


Kan Yabumoto

unread,
Jan 15, 2004, 7:14:47 AM1/15/04
to
"Dave" <dave(delete_this)@miraclecatDELETETHISTOO.com> wrote in message news:<DIqNb.54883$Rc4.210599@attbi_s54>...
> Hi all,
>
> Have a simple need to copy files from one folder to another (in W2K) that do
> NOT exist
> in the destination in a batch file using xcopy. The /U switch for xcopy
> only copies over files
> that already exist in the destination folder, but there is no switch to do
> the opposite.
> I figure an advanced batch program could do this, but I have no idea where
> to start.

When you are looking for a feature that is similar but not exactly
what XCOPY offers, give XXCOPY a try. Its command syntax is
very similar to XCOPY so it's relatively painless to learn.
But has many times more options to choose from (which takes
times to learn).

It's a freeware for personal use.

http://www.xxcopy.com

Here's what you want.

xxcopy \src\ \dst\ /BB // selects only files that are not in the dst.

Usually, for a serious job, you may want to include

/S // includes subdirectories
/H // includes hidden/system files.
/R // overwrites read-only file in the dst.
/KS // keeps source attributes exactly (even Readonly bit).

XXCOPY is written with the use in batch file in mind.
To learn more about XXCOPY, you may download the help file:

http://www.xxcopy.com/xxcopy.chm

Kan Yabumoto

Marco Maier Said

unread,
Jan 15, 2004, 7:25:27 AM1/15/04
to
"Davedelete_this" wrote in message <news:DIqNb.54883$Rc4.210599@attbi_s54> :

> it would overwrite the file. If the destination file is the same, it
> does not do an overwrite

echo n|xcopy /e /q sourcedir destinationdir
--
Best,
Marco

foxidrive

unread,
Jan 15, 2004, 7:38:23 AM1/15/04
to

Marco, that does not take the filesize, date nor time into account.

Marco Maier Said

unread,
Jan 15, 2004, 7:57:07 AM1/15/04
to
"foxidrive" wrote in message
<news:d9otgt2uibtb.1xg81kckofiy3$.d...@40tude.net> :

I read only the first few lines in wich he wrote:

"The /U switch for xcopy only copies over files
that already exist in the destination folder, but there is no switch to do
the opposite."

I thought it was all he needed!
--
Best,
Marco

Dave

unread,
Jan 15, 2004, 11:06:57 AM1/15/04
to
Thanks all!

I'll try the /D switch (I just now noticed it's default setting when no date
is specified - DOH!) for now while I test
XXCopy for compatibility on the NAS (Snap) box.

Dave


Marco Maier Said

unread,
Jan 15, 2004, 11:15:54 AM1/15/04
to
"Marco Maier Said" wrote in message <news:9x9ssd5hria$.dlg@MRC.MIR.SID.75> :

In fact,rereading the posting, it seems that he needs
a "no to all equivalent",so

if exist _t del _t
echo d|xcopy /e sourcedir destinationdir
set /a n=0
for /f %a in ('dir /b sourcedir') do set /a n+=1
for /l %a in (1,1,%n%) do echo n>>_t
type _t | xcopy /e sourcedir destinationdir
del _t

--
Best,
Marco

Mark V

unread,
Jan 15, 2004, 1:41:19 PM1/15/04
to
In alt.msdos.batch.nt Dave wrote:

Have you ruled out using replace.exe ?

0 new messages