Copying in Windows 7 command prompt

July 20, 2011 at 14:20:21
Specs: Windows 7
Hi, and thank you for helping! I'm a bit of a dizzy blonde, and though I've searched, all the answers are confusing me!

I have a folder. Lets call it c:\folder1. In it, are several levels of subfolders, and then finally, the files. The files are a selection of extensions, lets say .abc, .def, .ghi etc. A .def file may be 3 or 4 subfolders into c:\folder1.

What I'd like to do is copy all the .def files in the subfolders of c:\folder1 into m:\folder2, but directly. ie, I do not want to copy the subfolders too. So, I'd like to copy c:\folder1\subfolder1\subfolder2\subfolder3\*.def to m:\folder1\

How would I do this please?

Thank you :)

See More: Copying in Windows 7 command prompt

Report •

July 20, 2011 at 14:24:35
I should note that I'm in command prompt on Windows 7, so I don't know whether this is actually DOS? Suspect not...?
I first posted in the Windows 7 section, but wondered if my query would be better placed here.If not, please accept my apologies.

Report •

July 20, 2011 at 16:50:26
I'm not sure about windows 7 but previous OS's had XCOPY. A command such as:


would copy all the def files from the sub directories but would create the sub directores in the destination folder, which you don't want.

From the command prompt type XCOPY /? and enter for the available switches. Maybe windows 7 xcopy has a switch that will copy from subdirectories but not recreate them in the destination folder.

If not you might check XXCOPY, which is third party software very much like xcopy but with more options:

You can try the freeware package. I have a old version that runs from dos/command prompt. I'm not sure if the newer versions run from command prompt or windows.

Report •

July 21, 2011 at 02:42:48
Hi Dizi - from your original post, is this incorrect:-

"A .def file may be 3 or 4 subfolders into c:\folder1."

If so, please edit to correct as it is confusing.

I wondered if the windows search facility could be used to find the required files, then these could be copied to a folder of your choice.

Good Luck - Keep us posted

Report •

Related Solutions

July 21, 2011 at 12:16:15

Thank you. I've already had a look at XCOPY /?, and found that there aren't any handy little switches to do what I want. Then I came on the interwebby thingy and got confused!

I'll check out xxcopy, thanks muchly!

Report •

July 21, 2011 at 12:24:41
Hi Mike Newcomb

No, that is not incorrect. The structure is as follows:

C:\Folder1 > subfolder1 > subfolder2 > subfolder 3 (potentially)subfolder4 > .def file

I want to copy the .def file, and put it into:

M:\Folder1 > .def file

Thus ridding myself of all the unnecessary subfolders.

I don't want to do this manually, as there are nearly 5,000 files, each at the end of a string of subfolders.

Finding the files isn't a problem, the command "dir /s *.def" works beautifully. I just need a way of copying them without recreating all the subdirectories.

Report •

July 21, 2011 at 12:38:13
As an example, because it's hard to imagine why anyone would really mean what I say I do!
Imagine the structure is as follows:

Folder1 is actually named A-Z.
That contains 2 subfolders, A-L and M-Z. Lets use A-L...
In it, are no files, but 12 subfolders; A, B, C, D... and so on, up to L.
In subfolder A, are a bunch more subfolders, Aaron, Adam, Alan, Andrew, etc.
Aaron may very well contain the .def file, however Adam is more frequent, so may contain more subfolders - Jones, Smith, White. Then, in these, are the .def files. One in Jones, one in Smith, one in White etc.

The .def file will be titled Adam_Smith.def, so I have absolutely no use for the folder structure at all. It was simply a really, really poorly done disc that I had to copy onto C and hand back sharpish. Now I need to trim out all the carp, leaving myself with just the .def files.

Hope this explains a little :)

Report •

July 21, 2011 at 22:48:04
As Mike mentioned, you can probably do a search for *.def in c:\folder1. Then highlight/select all that are found and copy them to m:\folder1.

I had thought there was some point in doing it from command prompt and well, sometimes it's fun to do things in dos. But if you just need to get them copied and that's all then a search from windows is probably the way to go.

Report •

July 22, 2011 at 02:59:11
Yeah, I can do that. I thought that it'd be a tad quicker in command prompt though, it reckons it'll take nearly 17 hours from windows!!

Report •

July 22, 2011 at 11:18:16
Window PowerShell is built into Windows7 and makes this a piece of cake, it will take longer for you to find it in the start menu than it will take to move all the files!

dir c:\folder1 -recurse -include *.abc
will return all the files under c:\folder1 with the extention .abc

then it is just a copy away!!!

copy (dir c:\folder1 -recurse -include *.abc) C:\folder2

Report •

July 23, 2011 at 02:26:31
Hi Dizy - sad to admit, but if anything am now more confused, and would like to rectify this.

In true dos, they were called directories but are now called folders. It is my understanding:-

a) a folder
can contain subfolders and/or files
(possibly) can have an extension to its name

b) a sub-folder
can contain subfolders and/or files
can have an extension to its name

c) a file
will have an extension to its name, even if not used

This gave rise to the term 'tree' or 'tree structure' which starts at the top and works down. Some may remember the most useful utility XTree.

Would appreciate confirmation my above understanding is correct.

This is why I find Dizi's wording and further explananation unclear.
Does the .def extension apply to subfolders, files, or both?

Good Luck - Keep us posted.

Report •

July 23, 2011 at 21:43:37
Yeah, dos 'directories' are windows 'folders' and can have extensions as do files.

Files don't have to have extensions.

I don't think diziblond's directories/folders have extensions but the search need not specify a directory extension. For example, the xcopy switch /s includes all subdirectories regardless of their name. (I'm not familiar with windows 7 command switches and can't test James' idea.) She just wants all the files with a .def extension in c:\folder1 and its nested subdirectories to be copied to a single directory, m:\folder1, without the directory structure they occupied in c:\folder1.

Report •

Ask Question