As part of a recent project to migrate a single file server to a new DFS structure spanning multiple file servers I had the need to copy folder structures to a certain level without copying any files. The key thing was to ensure that the NTFS permissions were migrated which would save me time rather than recreating them.The easy one liner which I used looked a little something like this. Page formatting may put this on multiple lines but it should be on one line.
Robocopy "D:\Source Directory\SubFolder" "\\DestinationServer\share$" /e /LEV:4 /z /SEC /XF * /LOG+:migration.log /TEE
You can find out what each part does by running Robocopy /? but in brief:
/e – copy subdirectories, including empty ones
/LEV:4 – only copies the folders up to 4 levels deep, anything below this is ignored. In my case these will be captured by a later script to move files.
/z – turns on restartable mode. This is a little redundant here as we are not copying any files but good practise to include it for when files are copied.
/SEC – tells the copy to take all attributes including NTFS ACLs and timestamps
/XF – Exclude Files matching any given name, in this case * is given ensuring all files are skipped.
/LOG+:migration.log – This will create a log of the output from the command and append to it each time it is run, useful for going back to check mistakes later on. Note unless specified it will put this in the current directory or where the .bat is being run from.
/TEE – Outputs to the console window as well as the log file, this just allows you to see what is going on.