57

I have a folder with a lot of subfolders and files in them. Is there a way to copy the folder and subfolders directory structure without copying the files they contain, using cmd or powershell?

9 Answers 9

53

This will copy the complete sub-directory structure contained in the source directory to the destination directory without including any files.

xcopy <source> [<destination>] /t /e
Option Description
/t

 
Copies the subdirectory structure (that is, the tree)
only, not files. To copy empty directories, you must
include the /e command-line option.
/e
 
Copies all subdirectories, even if they are empty.
Use /e with the /s and /t command-line options.

Microsoft Documentation:   xcopy command

2
  • 1
    correct, /e should be used, too.
    – user286640
    Jan 9, 2016 at 16:13
  • 1
    XCOPY Build in Powershell by default and works perfectly.
    – BenCes
    Jan 28, 2016 at 14:51
30

Yup. XCOPY

XCopy source {destination}  /t

example

xcopy C:\Folders D:\Folders /t

more about xcopy can be found here http://ss64.com/nt/xcopy.html

1
  • 6
    You should add /e to copy also empty folders
    – user286640
    Jan 9, 2016 at 16:12
28

Although XCOPY still works, Windows Vista and later include ROBOCOPY which has more features. General syntax for copying a folder tree (including empty folders) without the files is:

robocopy "A:\Source folder" "B:\Destination folder" /e /xf *

1
  • /COPYALL should also take care of security info (ACLs)
    – Mark Sowul
    May 25, 2023 at 19:20
4

PowerShell method that doesn't require copying each file and then deleting them:

Copy-Item -LiteralPath '.\source' -Destination 'C:\path\to\copy' -Recurse -Filter {PSIsContainer -eq $true}

Or more succinctly:

copy .\source C:\path\to\copy -r -fi PSIsContainer

The only interesting trick here is the filtering on the PSIsContainer property, which is true for directories but not files.

1
  • This is super quick as well!
    – Regmi
    Jul 30, 2019 at 22:36
0

I just used the freeware Miroirs, which very simply copied just folders, not the contents (though that is an option).

http://www.scanialabs.com/Products/Miroirs/Miroirs.aspx

0

Look at 47folders app, free, handy Windows tool, does exactly what you need through nice GUI. enter image description here

WARNING: Former link (http://47foldersapp.com/) now (Nov 2017) leads to advertisement for clothing.  The last good Internet Archive copy is here.  Software may still be available from freeware download sites such as this one.

-1

There's probably a better solution, but I'd see these:

  • Copy everything, then empty the folders with a script.

  • Make a script that will copy everything if it has no extension. Unless you have files without an extension in the folders, which you shouldn't, it should work, because, well. Folders don't have extensions. Something that would look like this in pseudocode:

open_directory($path);
while($file=get_directory_content) {
if(empty(get_file_extension($file))) {
copy_the_file($file,$destination);
}
}
close_directory;

2
  • Unfortunatelly, we do have files without extensions. From .placeholders for code repos, to some specific data files.
    – Rook
    Jan 9, 2013 at 7:00
  • Oh. Well. Maybe there's an if(it's a folder) thing, then. But uhm. The xcopy thing above seems like it's the right thing for you then. Unless it's not, in which case you can run a script to 1. copy all folders and 2. empty all folders. Or something. But this is... Long. xD
    – Ariane
    Jan 9, 2013 at 7:19
-1

as far as I know there are third party software which may provide this functionality if you want to do with command prompt then copy command is out there. type help copy in cmd which provides details on how you copy files through cmd.
after copying go to the folder through cmd and run command

del*.*
which deletes files because folders not having . character

1
  • 3
    Deletes files all right, but who says folder names cannot contain a dot/period as well?
    – Karan
    Jan 9, 2013 at 18:11
-1

Use PowerShell to do that using. Make Copy of Folder and then Remove-Item -Path "C:\test\*.*" -recurse

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .