Page 1 of 1

Copy and rename on one command line

Posted: 03 Jul 2021 09:46
by falcios
This is a sample script

robocopy "c:\users\test" "d:\test" "sample.txt" /xf desktop.ini /np /tee /ndl /xx
echo.
if exist "d:\test\sample.txt ren “Sample June 2021” Exit 2 ********
echo.


in the command line if exist "d:\test\sample.txt ren "Sample June 2021" Exit2
I want to copy and rename at the same time and it's not working

Can the copy and rename be on one command line, if so, how do I go about doing that?

Thanks in advance.

Re: Copy and rename on one command line

Posted: 03 Jul 2021 09:50
by rasil
You can combine 2 commands together with a &

for example

Code: Select all

echo hello&pause>nul

Re: Copy and rename on one command line

Posted: 03 Jul 2021 10:07
by falcios
Thanks Rasil for your reply.

How would I combine the 2 commands together on one line.

if exist "d:\test\sample.txt ren “Sample June 2021”

I can't figure out how to make it work using your example.

Can you help?

Re: Copy and rename on one command line

Posted: 03 Jul 2021 10:20
by aGerman
How would REN know what file you want to rename?

Code: Select all

if exist "d:\test\sample.txt" ren "d:\test\sample.txt" "Sample June 2021.txt"
Also, take care that you don't miss quotes (should usually be an even number in a line) and that you use the right quotation marks ("" rather than “”).

Steffen

Re: Copy and rename on one command line

Posted: 03 Jul 2021 11:12
by falcios
Thanks to aGerman, Rasil, It worked. You're gurus.