Search code examples
windowsbatch-filedirectoryfilesystemsdirectory-structure

Replicate a directory file structure with empty files


I have a directory with this structure (real use case: thousands of files, 400GB directory!):

mydir/
|---- blabla.mp4         3.2 GB
|---- foo/
       |----- blup/
       |----- test.wav   245 MB
       |----- test.txt   12 KB
|---- xyz/
       |----- test2.txt  10 KB
|---- zzz.wav            100 MB

How to replicate the tree structure + filename structure and get this, with Windows?

mydir_structure/
|---- blabla.mp4         0.0 KB
|---- foo/
       |----- blup/
       |----- test.wav   0.0 KB
       |----- test.txt   0.0 KB
|---- xyz/
       |----- test2.txt  0.0 KB
|---- zzz.wav            0.0 KB

Solution

  • From windows vista, robocopy is included in the OS (for previous versions there is a download from Microsoft)

    robocopy \mydir \mydir_structure /create /e
    

    /e indicates a recursive copy including empty folders.

    /create creates the empty files in the target hierarchy.