How To: Copy all the files in a directory to another directory using the command line

01/26/09

Permalink 10:57:34 am, by dave Email , 263 words, 1076 views   English (US)
Categories: Microsoft Tools, Using the Command Line

How To: Copy all the files in a directory to another directory using the command line

It is very straight forward to copy the contents of one directory or folder to another folder using the copy command from the command line.

C:\myfiles>copy * C:\test

This command copies all the files in the C:\myfiles directory to the C:\test directory. This works very well if you are just copying the files from one directory to another and not needing to rename the files.

[More:]

If you need to rename the files you are copying,it takes just a little more work.

C:\myfiles>for /f %j in ('dir /a:-D /b') do copy %j C:\test\%j.bak

This command copies all the files in the C:\myfiles directory to the C:\test directory and renames then with a .bak extension. A for statement is used to go through the results of the dir command. The dir command in this example only returns the names of the files ( the folders are ignored with the /a:-D argument and the /b gets rid of everything but the name of the file ). For each file name that is returned from the dir command, it is passed to the copy command. The copy command then copies the files to a new location with a new file extension. In this case, we are renaming the files using a .bak extension.

I hope this post was of some use to you. If it isn't, I am always looking for topics to dicuss so submit a request for your question or need and I will see if I can answer it.

Dave



Did you like this post? If so, Share it!  del.icio.us digg reddit slashdot this article Facebook Twitter MySpace Email



Pingbacks:

No Pingbacks for this post yet...

This post has 1 feedback awaiting moderation...

Windows Tools & Utilities

A place to share interesting and cool windows related tools, utilities, and applications that might be helpful to folks.

Search

Follow Me:

Misc

Who's Online?

  • Guest Users: 1

powered by b2evolution free blog software