Walter Schrabmair
Walter Schrabmair

Reputation: 1341

How to create a fake/dummy Windows tree from other Windows tree with Windows shell?

I have a big Windows directory and file tree. Now I need to copy this tree to another location but I do not want to copy the contents from each file. Only the structure and filenames with 0 bytes contents are needed. How could this be done with as cmd shell in Windows 10?

What I did:

  1. xcopy /t e:\oldtreedir e:\new\oldtreedir
  2. dir /a /b /s > mybat.bat
  3. edit mybat.bat to:

    replace \ne:\ to 
    \ncopy nul e:\new\
    

    so that it is for each filename the line

    copy nul e:\new\oldtreedir\file1.txt
    

I had to edit the mybat.bat. Could this be done by a script in the Windows command line?

PS: I found this: WIN-PRg but this program do not create a dir-tree. All files are in one dir only.

Upvotes: 0

Views: 987

Answers (2)

aschipfl
aschipfl

Reputation: 34919

If I got your question right, robocopy should do the trick:

robocopy "E:\oldtreedir" "E:\new\oldtreedir" "*.*" /E /CREATE

Upvotes: 3

Stephan
Stephan

Reputation: 56180

No need to create an additonal batch file:

@echo off
setlocal enabledelayedexpansion

xcopy /t e:\oldtreedir  e:\new\oldtreedir

for /f %%a in ('dir /b /s /a-d "e:\oldtreedir\*"') do (
  set "file=%%a"
  set "file=!file:E:\=E:\new\!"
  break>"!file!"
)

Upvotes: 1

Related Questions