22. February 2013 · Comments Off on Copying Directory Structures without Files · Categories: Batch Files, Command-line Tools, Windows · Tags: File Tools, Freeware/Open Source
Last updated on 09/25/2022

Recreating directory structures can be a tedious and error-prone chore, especially if using the right-click method to create multiple structures and folders. This guide describes three methods to easily copy directory structures (without files) in Windows: (1) with the command line, (2) with GUI tools dedicated for that purpose, and (3) by configuring a freeware file manager, FreeCommander, to enable this function.

https://clker.com

Copying Directory Structures from the Command-line

For those comfortable with the command-line, two commands that can be used for this purpose are the Xcopy and Robocopy, both of which have tons of options. Although others, such as the FOR command could also be used, Xcopy and Robocopy are by far the most popular tools used for this purpose.

Xcopy

Xcopy is included in systems up to Windows 8. XCOPY stands for extended copy. It’s a more powerful version of copy with additional features that can copy files, directories, and whole drives. Note that although Xcopy is included with most versions of Windows, it has been deprecated in favor of RoboCopy.

To use Xcopy to clone a directory without files, use the following syntax:

xcopy /t /e "C:\Your Folder" "C:\New Folder"

/t = Copies the subdirectory structure, but not the files

/e = Copies subdirectories, including any empty ones

When using Xcopy with the above switches, you may be asked to specify whether the target is a directory or a file before the Xcopy command executes, but if the command is executed from a batch file, no user interaction is required.

Note: Xcopy doesn’t display any progress or completed operations information when executed. If the target directory doesn’t exist, it will be created.

Additional Xcopy commands can be found here.

Robocopy

Robocopy stands for “Robust file copy.” It’s a standard feature for Windows starting with Vista. It’s can also be installed in WinXP as part of the Windows Resource Kit.

To use Robocopy to clone a directory without files, use the following syntax:

robocopy "C:\Your Folder" "C:\New Folder" /e /xf *

same as above but without displaying the status:

robocopy "C:\Your Folder" "C:\New Folder" /e /xf * >nul

same as first example and creates a log (overwrites existing log):

robocopy "C:\Your Folder" "C:\New Folder" /e /xf * /log:yourlogfile.log

same as first example and appends to log (appends to existing log):

robocopy "C:\Your Folder" "C:\New Folder" /e /xf * /log+:yourlogfile.log

Copy only the top level sub-folders (sub-folders in the source directory)

robocopy "C:\Your Folder" "C:\New Folder" /e /LEV:2 /xf *

/e = Copies subdirectories, including empty ones.

/LEV: n = Copy only the n LEVels of the source. For n=2, only the top level sub-folders will be copied

/xf = Excludes files matching the specified names or paths. Wildcards “*” and “?” are accepted

Additional Robocopy commands can be found here.

Note: Robocopy displays progress and completed operations information when executed as shown in the below screenshot. If the target directory doesn’t exist, it will be created.

 

Download example xcopy and robocopy batch files:

  xcopybatch.bat (582 bytes, 3,433 hits)

  robocopybatch.bat (653 bytes, 2,785 hits)

Note: Remove the .txt extension before using either batch file.

 

Freeware GUI Tools for copying Directory Structures

Two easy-to-use GUI (graphical user interface) apps dedicated specifically to creating directory structures without files are TreeCopy and Miroirs:

TreeCopy – Portable and freeware. Runs on Win95 to Win8.

treecopy screenshot

Miroirs – Freeware. Requires installation. Runs on XP/Vista/Win7

Miroirs screenshot

xcopy Frontend – Freeware. Portable. Runs on Windows XP or later. Provides an overview of all available parameters and makes it easy to select the needed parameters. Each parameter can be activated by clicking on it. The finished command line can be copied or executed directly.

 

FreeCommander setup to copy Directory Structures

FreeCommander is a freeware file manager that can be configured to copy directory structures using a customized batch file with the Xcopy and/or Robocopy commands. FreeCommander Ver. 2009.02b was used for this example. These instructions are modified from those provided on the FreeCommander forums.

FreeCommander Instructions

Create a batch file with the following code and save it with any name desired such as “copyFolderStructure_freecommander.bat.” For Xcopy the batch file’s main code consists of:

xcopy %1 %2 /t /e

%1 and %2 are the first and second parameters passed to the batch file (structure to copy and target)
The /t and /e options are the same as above

For Robocopy the batch file’s main code consists of:

robocopy %1 %2 /e /xf *

%1 and %2 are the first and second parameters passed to the batch file (structure to copy and target)
the /e and /xf * options are the same as above

 

Download example xcopy and robocopy batch files for FreeCommander:

  freecommander_xpcopy.bat (763 bytes, 923 hits)

  freecommander_robocopy.bat (773 bytes, 777 hits)

 

Note: a pause may be entered at the end of either of the batch files below to keep the command window open for viewing the output. Remove the _.txt extension before using.

 

From the menu, select Extras->Favorite Tools->Edit or use (SHIFT+CONTROL+Y). Click the image below to enlarge.

freecommander menu

Select none from the left-hand column named Categories, then click once in the Items column.

FreeCommander Tools Configuration

Use the Items:Add to list button that appears above the Items column to create an item, for instance Copy Folder Structure.

Select Seek program by clicking the blue arrow next to the program field to navigate to and select the saved batch file’s (e.g. C:\tools\copyFolderStructure_freecommander_robocopy.bat) full path into the program field.

Enter the following into the parameter field:

"%LeftDir%" "%RightDir%" %Dlg%

The variables, %LeftDir% and %RightDir%, pass the address of the left and right folders to batch file parameters %1 and %2. The %Dlg% variable is optional and may be omitted if desired. It is used to display a Run program window (screenshot below) before actually starting the script to allow the folder names to be verified. It also provides a way for the operation to be cancelled.

dialog

If desired, add an icon by using the blue button next to the icon field to navigate to the icon’s location.

Make sure the boxes are checked as in the Define Favorite Tools screenshot above before hitting OK.

Tool Selection
The toolbar now contains an entry for copying Folder Structures. The tool can be selected from the menu with Extras->Favorite Tools->Name of your tool or by using the favorites icon (make sure Extras is enabled in Extras->Settings->View->Toolbar if it’s not visible on the toolbar).

Using FreeCommander

To use, select the structure to copy in FreeCommander’s left pane and select the target directory in the right pane. Select and click your tool from the toolbar or menu as described above. After the Run program dialog appears, click OK to continue.

FreeCommander Select

Xcopy doesn’t provide an option to display progress or completed operations. However, with Robocopy, the output will display the copy operation details as shown below (a pause was used in this batch file):

RoboCopy Output

Robocopy Output

If no errors occur, the folder structure will be copied as in the following screenshot:

FreeCommander copied

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Print Friendly, PDF & Email
Share
profile
">Bear

Bad Behavior has blocked 1966 access attempts in the last 7 days.

Spelling error report

The following text will be sent to our editors:

participate