Copy and rename on one command line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Copy and rename on one command line

#1 Post by falcios » 03 Jul 2021 09:46

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.

rasil
Posts: 31
Joined: 23 Apr 2020 13:05

Re: Copy and rename on one command line

#2 Post by rasil » 03 Jul 2021 09:50

You can combine 2 commands together with a &

for example

Code: Select all

echo hello&pause>nul

falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Re: Copy and rename on one command line

#3 Post by falcios » 03 Jul 2021 10:07

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?

aGerman
Expert
Posts: 4198
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy and rename on one command line

#4 Post by aGerman » 03 Jul 2021 10:20

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

falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Re: Copy and rename on one command line

#5 Post by falcios » 03 Jul 2021 11:12

Thanks to aGerman, Rasil, It worked. You're gurus.

Post Reply