xcopy file copy batch

Bfg technologies Bfg nvidia geforce 260...
January 18, 2010 at 05:31:04
Specs: Windows XP
Trying to use xcopy to copy a file from a few servers to a destination server. I want the same file to be copied from multiple servers and all files to placed in the same directory on the destination server but the file renamed to sourceserver-filename.

The problem being is it prompts if it is a file or directory. Can it be set to file or bypass prompt?

@echo off
set server1=server1
set dest1=server2\data\home\user
set file1=sys\tivoli\TSM\CLIENT\BA\dsmerror.log
  
xcopy \\%server1%\%file1% \\%dest1%\%server1%-dsmerror.log

Thanks!
Michael


See More: xcopy file copy batch

Report •


#1
January 18, 2010 at 06:06:39
The sim[lest way to avoid the dumb question is to use a final backslash.

set dest=c:\files\

Beyond that, for individual files and no need to create directory struct, you could use plain vanilla COPY.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 18, 2010 at 06:06:54
*sigh* It's Monday, and already I'm bored.
echo f|xcopy \\%server1%\%file1% \\%dest1%\%server1%-dsmerror.log


Report •

#3
January 18, 2010 at 06:09:23
Hi R2,

I guess that qualifies as a photo finish. 15 seconds apart.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
January 18, 2010 at 06:11:03
I know; I shouldn't have mentioned I was bored. Then I'd be first. =P

Report •

#5
January 18, 2010 at 06:40:55
Is it just me or have there been more than the usual load of long, confused threads here lately?

OT: Is today a US holiday? NYSE closed.


=====================================
Helping others achieve escape felicity

M2


Report •

#6
January 18, 2010 at 06:55:42
Thanks guys.. quick as always.

How would I throw a date stamp on the end of it? I've tried %date% but it creates folders instead.


Report •

#7
January 18, 2010 at 07:04:46
@echo off & setLocal enableDELAYedexpansion

call :YMD14
echo copy bla c:\files\%YMD%-bla

goto :eof

:YMD14
::== YMD14.bat

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set DD=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set DD=%%a
echo Date %DD%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set MM=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set MM=%%a
echo Month %MM%

year
if errorlevel 215 set YYYY=2007
if errorlevel 216 set YYYY=2008
if errorlevel 217 set YYYY=2009
if errorlevel 218 set YYYY=2010
if errorlevel 219 set YYYY=2011
if errorlevel 220 set YYYY=2012
echo Year %YYYY%

set YMD=%YYYY%%MM%%DD%
echo YMD is: %YMD%

del day.com
del month.com
del year.com
del dat.com

::============================ DONE YMD14 ==========================

goto :eof


=====================================
Helping others achieve escape felicity

M2


Report •

#8
January 18, 2010 at 07:22:12
Alternatively, you could do something like the following (not guaranteed to work):
for /f "tokens=2-4 delims=\/ " %%a in ("%date%") do @echo %%a-%%b-%%c

Mechanix2Go: OT: Is today a US holiday? NYSE closed.
Yes


Report •

#9
January 18, 2010 at 07:31:45
Hi R2,

gives me:

18-01-2010--


=====================================
Helping others achieve escape felicity

M2


Report •

#10
January 18, 2010 at 07:35:48
Mechanix2Go: gives me:
Razor2.3: (not guaranteed to work)
But it did, more or less. So yay. And stuff.

Report •

#11
January 18, 2010 at 08:14:12
Hi M2,

That debug script picks on the one and only(to my knowledge) difference between .cmd and .bat, which I only just found out about.

It's some screwy behavior relating to errorlevels(set on check). It's not evident if it's a bug or not, but it's there (on xp at least). So that script needs to be run as a .bat to run as is(which isn't really much of an issue).

C:\Documents and Settings\judago>xd

D:\Home\DATA>NEW.CMD
Date 01
Day Sunday
Month 01
Year 2007
YMD is: 20070101
copy bla c:\files\20070101-bla

D:\Home\DATA>ren new.cmd new.bat

D:\Home\DATA>new.bat
Date 19
Day Tuesday
Month 01
Year 2010
YMD is: 20100119
copy bla c:\files\20100119-bla

D:\Home\DATA>


Batch Variable how to


Report •

#12
January 18, 2010 at 08:16:19
Thanks.. I've almost got a simpler method but can't get the year to work.

set mm=%Date:~3,2%
set dd=%Date:~0,2%
set yy=%Date:~2,4%

echo f|xcopy \\%src17%\%file1% \\%dest1%\%src17%-dsmerror-%dd%%mm%%yy%.log


Report •

#13
January 18, 2010 at 08:26:57
The date variable is settings dependent. If you want to use substrings and make it dependent on your settings then you will need to get the positions right.

set mm=%Date:~3,2%
set yy=%Date:~2,4%

This is setting mm to the two characters after position 3 and yy to the four characters after position 2. Can you see how they overlap?

If you post the output of "echo %date%" we can help with the substrings, if that is the direction you want to go.


Batch Variable how to


Report •

#14
January 18, 2010 at 08:46:40
Hi Judago,

I've never used .cmd; LOL

It's not quite midnight here in time zone +7 so I wonder if you're between here and the date line or your cloack/calendar is set wrong.


=====================================
Helping others achieve escape felicity

M2


Report •

#15
January 18, 2010 at 08:56:12
I've almost got a simpler method but can't get the year to work.
H:\>echo %date:~2,4%
n 01

The FOR method tends to be the least error prone, assuming you tailer it to your localization.

Judago: That debug script picks on the one and only(to my knowledge) difference between .cmd and .bat, which I only just found out about.
Insert some ECHOs and you can see the best part:

Date EL: 18
Date 01
Day EL: 1
Day Sunday
Month EL: 1
Month 01
Year EL: 218
Year 2007
YMD is: 20070101


Report •

#16
January 18, 2010 at 10:23:04
@M2: +10 here and 0430 atm(- about two for my last post)

Edit:

@Razor: Here's a little more info, though not much:

Double edit: The .com's do leave the correct errorlevel it's just the for loop and/or checking the errorlevel that way that seems to do it.


Batch Variable how to


Report •

#17
January 18, 2010 at 11:34:43
Yep got it now..

set yy=%Date:~6,4%

Thanks for your help guys!


Report •

#18
January 19, 2010 at 08:50:52
> The sim[lest way to avoid the dumb question is to use a
> final backslash.
>
> set dest=c:\files\
>
> Beyond that, for individual files and no need to create
> directory struct, you could use plain vanilla COPY.
>

I don't get it, if you put a backslash at the end ... you would be XCOPYing to a directory anyway, no ?

The whole issue is that the target is a file.

For me, it's a bug, since I consider XCOPY as a command to copy files AND directories, and it simply does not like the fact that a target is a file, it keeps on asking the obvious stupid question. Using COPY instead, is a bit of a lame excuse, escpecially since you know that XCOPY is relatively "low" on features, so any advice to use COPY instead, is rather silly, no ?!

You could better use Robocopy, even if not default in XP, just take it from the Microsoft site.

Anyway, the best bugfix I have for this problem, is to create the file before copying, ex.

echo dummy > target
xcopy source target

Asking MS to fix this bug, is useless, I guess, since they would say it's not a bug.


Report •

#19
January 19, 2010 at 08:54:16
Micka, if you run the script itself on the source server, don't do this :

set server1=server1

... but just use variable %COMPUTERNAME% instead.


Report •

#20
January 20, 2010 at 00:16:48
"I don't get it, if you put a backslash at the end ... you would be XCOPYing to a directory anyway, no ?

The whole issue is that the target is a file. "

yep & yep

but heis only copying one


=====================================
Helping others achieve escape felicity

M2


Report •

#21
January 23, 2010 at 06:16:24
That's what I am saying, enough options to indicate copy to a directory, but none to indicate copy to a file ...

Report •


Ask Question