Check for file if exist and rename it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
imgro0t
Posts: 4
Joined: 05 Feb 2016 06:55

Check for file if exist and rename it

#1 Post by imgro0t » 09 Feb 2016 07:53

Hey guys, im coding a script , trying to automatize some task i use all days... so im gonna copy the script to make you an idea how its must look like

Code: Select all

@echo off

set /P servidor_inicial = server_
set /P servidor_final = server_
xcopy /s \\server_%servidor_inicial%\fasapos\posdpofe.dbf \\server_%servidor_final%\fasapos

pause


all i want is to copy the posdpofe.dbf file from server_xxx to final server... but i become the error The specified unity is not valid. 0 files copied from.

can anyone help me ? i m stuck at this..

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

Re: Check for file if exist and rename it

#2 Post by Squashman » 09 Feb 2016 08:05

You need to remove the spaces. The spaces are actually part of the variable name.

You can test this right from the cmd prompt.

Code: Select all

H:\mount>set /P servidor_inicial = server_
server_MyServer

H:\mount>echo %servidor_inicial%
%servidor_inicial%

H:\mount>echo %servidor_inicial %
MyServer

H:\mount>

Notice that when I put the space in the variable name it then displays the contents of the variable on the screen.

imgro0t
Posts: 4
Joined: 05 Feb 2016 06:55

Re: Check for file if exist and rename it

#3 Post by imgro0t » 09 Feb 2016 09:50

Oh thanks u were right about the spaces... i remove them and i become what i needed... thank you to the option of code you showed me im gonna use them too...

Post Reply