Helping people with computers... one answer at a time.

Windows Explorer is a fine tool, but there are still a few things you can't easily do with it. This calls for the Windows Command Prompt.

I would like to be able to copy a file but at the same time rename it, so when it gets to the destination folder it has whatever file name I want it to. Do you know of a way to accomplish this in one step?

Not using Windows Explorer, no.

However it's a snap using the Windows Command Prompt.

In Windows Explorer, when you drag and drop a file from one location to another, you must let the copy (or move) operation complete before you can then rename the file in its new location.

However, using the COPY command in the Windows Command Prompt, you can do it in one quick step.

Start by firing up a command prompt - usually Start, All Programs, Accessories, Command Prompt. You'll probably get something like this:

Command Prompt

The COPY command has the following syntax:

COPY source destination

The "trick" here, if you want to call it that, is that the destination can either be the folder to receive the file, or it can include the new filename.

For example:

Command Prompt with a simple file copy

This command:

copy current.txt "My Documents"

Executed with "C:\Documents and Settings\LeoN" as the current directory, copied "C:\Documents and Settings\LeoN\current.txt" to "C:\Documents and Settings\LeoN\My Documents\current.txt".

Now, this time we'll specify a filename:

Command Prompt with a simple file copy and rename

"...the Command Prompt, while somewhat arcane for the average user, is incredibly powerful."

This time we copied "C:\Documents and Settings\LeoN\current.txt" to "C:\Documents and Settings\LeoN\My Documents\copy.txt". In other words we copied the file, and gave the copy a new name in one operation.

These examples all assumed that the file you want to copy is in the "current directory" (or current folder), as listed in the command prompt itself. You can change directories with the "CD" command:

Command Prompt having executed a CD

Now your COPY operations will be relative to the new current directory.

Alternatively the COPY command will work with full paths as well, eliminating any reliance on the current directory:

Command Prompt having executed a copy using full paths

This example performed the same copy-and-rename we did earlier, but doesn't rely on any assumptions about the current directory. It specifies a full path to both the source and destination.

As you can imagine, the Command Prompt, while somewhat arcane for the average user, is incredibly powerful. Depending on your plans, it could be well worth spending a little time learning more about.

Article C2956 - March 7, 2007

Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

Recent Comments
6 Comments

In an OS long, long ago there was quite a performance difference between COPY and XCOPY.

COPY was part of the command interpreter that loaded very quickly and moved smaller files very well. XCOPY was a .EXE that took longer to load, but moved larger files quicker - due to a larger buffer.

These days it appears that the only real difference is the depth of features in XCOPY. Do you know if there is still a performance difference?

Posted by: dave b at March 8, 2007 1:15 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I assume that any actual performance difference between the two has long
since been overshadowed by the increase in both media and processor
speed. I'm sure that the differences you mention are still there, but so
small as to be unnoticeable these days.

Leo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)

iD8DBQFF8ex/CMEe9B/8oqERAkP0AJ9U1Vq4Rp6VqHHG89ohXJBnUblc5ACeOBzq
jhejEqH5ppse9AWxaF7wP1Q=
=VGYr
-----END PGP SIGNATURE-----

Posted by: Leo Notenboom at March 9, 2007 3:23 PM

I have a folder in My Documents that needs to be renamed. "C:\Documents and Settings\Julia\..." The folder is the \Julia\ folder. When I right click to delete it there is a message that this folder cannot be deleted. How do I rename a name on this computer that is no longer related to the computer or the files in it?

Folders at that level in Documents and Settings are ... special. They represent user accounts on the machine. The only way to remove them is to delete the user account "Julia", but remember that anything associated with that account will also be lost.
- Leo
01-Mar-2009

Posted by: John Everett at March 1, 2009 1:34 AM

Can I copy a file to another folder and rename the file where I copy the current date into the file name? So for example I want to copy test.txt to another folder but have it saved with the name 13032009test.txt.

Posted by: Markus Anzenhofer at March 13, 2009 1:47 AM

What I need to do is copy logfiles and rename them.

copy ex010101.log to ex010101a.log into another directory

Posted by: st at February 3, 2010 10:19 AM
Post a comment on "Can I Copy and Rename a file in a single step?":





Remember Me?

(You may use HTML tags for style)

Before commenting, please...

  • READ THE ARTICLE. A comment that shows you didn't will be deleted and ignored.

  • Comment only on the article. Use the search box at the top of the page if you have a question about something else.

  • NO PERSONAL INFORMATION in the comment. No email addresses. No phone numbers. No physical addresses.

  • Anything that looks the least bit like spam will be deleted. Links to unrelated sites or links that appear to be primarily promotional will be deleted, or the comment will be deleted.

  • Don't ask me to recover lost passwords or hacked accounts. I can't. Those comments will be deleted.

  • I can't respond to every comment. And I can't vouch for the accuracy of others who do.

Please wait. Your comment is being processed ...