copy files with exclude

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

copy files with exclude

#1 Post by mor.bas » 15 Jan 2014 08:49

Hi,
I need batch file that can use xcopt,robocopy...
It's copy from source to dest only the files that on dest are empty files(with 0 size).
like copy not overwrite but only for empty files on dest...
Thanks in advance...

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: copy files with exclude

#2 Post by Squashman » 15 Jan 2014 11:06

Well I think you would start by using a for loop to check the file size of the destination files.
If the File size is Zero Then use an IF EXIST command to see if the same file name exists in the source and If it does then copy the source to the destination.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy files with exclude

#3 Post by foxidrive » 15 Jan 2014 21:11

Robocopy has the /MAX:0 switch that will exclude files bigger than n bytes. Here it is shown with 0 bytes.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: copy files with exclude

#4 Post by Squashman » 16 Jan 2014 06:13

foxidrive wrote:Robocopy has the /MAX:0 switch that will exclude files bigger than n bytes. Here it is shown with 0 bytes.

But I would assume that would be for the source file and not the destination.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy files with exclude

#5 Post by foxidrive » 16 Jan 2014 07:16

Yes, that's right. I hadn't considered that the OP had created zero byte files in the destination.

Hmmm, he says this:

like copy not overwrite but only for empty files on dest...


I'm a little confused. So copy but not overwrite zero byte files.

Xcopy with /D can do that if you update the timestamps on all the zero byte files.
That might work.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: copy files with exclude

#6 Post by Squashman » 16 Jan 2014 07:26

foxidrive wrote:Yes, that's right. I hadn't considered that the OP had created zero byte files in the destination.

Hmmm, he says this:

like copy not overwrite but only for empty files on dest...


I'm a little confused. So copy but not overwrite zero byte files.

Yes. Technically you would have to overwrite them in the destination.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy files with exclude

#7 Post by foxidrive » 16 Jan 2014 07:28

Xcopy with /D can do that if you update the timestamps on all the zero byte files with a script.

That might work.

EDIT:

It's copy from source to dest only the files that on dest are empty files(with 0 size).


Hmm Now I am confused again.

mor.bas, which files are meant to be excluded? The zero byte files? Or every file which is not zero bytes?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: copy files with exclude

#8 Post by Squashman » 16 Jan 2014 08:53

foxidrive wrote:Xcopy with /D can do that if you update the timestamps on all the zero byte files with a script.

That might work.

EDIT:

It's copy from source to dest only the files that on dest are empty files(with 0 size).


Hmm Now I am confused again.

mor.bas, which files are meant to be excluded? The zero byte files? Or every file which is not zero bytes?

I think they really meant to say include and not exclude. If you want to copy the zero byte files that would be an include.
If you don't want to copy zero byte files in the destination then it would be an exclude.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: copy files with exclude

#9 Post by foxidrive » 16 Jan 2014 09:00

It says exclude in the thread subject, so I followed with that.

Post Reply