How to copy directories and files as empty files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
benjib77
Posts: 2
Joined: 27 Aug 2012 03:40

How to copy directories and files as empty files

#1 Post by benjib77 » 27 Aug 2012 03:48

I'm looking for a batch-script to copy a directory with a lot of sobfolders and files. There are also directories with over 3000 subdirectories and files. So I need a quick way to copy all the subfolders and files. It's also important to copy the files as empty (0-byte) files to the target. So finally I would get the same directory-tree and the same files with 0-Byte filesizes.

Is this possible in a comfortable way?

(sorry for my English, I'm from Switzerland ;))

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: How to copy directories and files as empty files

#2 Post by abc0502 » 27 Aug 2012 04:24

so all what you need is something like a photo of all the directory tree, no data just image of all folders and files names

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to copy directories and files as empty files

#3 Post by foxidrive » 27 Aug 2012 04:27

This should create a directory tree with zero byte files.

Run it from the base folder you want to duplicate. Currently it will create it in c:\backup\
If you have empty folders to reproduce then an extra step will be needed.

Code: Select all

@echo off
set "target=c:\backup\"

dir /a:-d /b /s>list.tmp
for /f "delims=" %%a in (list.tmp) do (
md "%target%\%%~pa" 2>nul
type nul >"%target%\%%~pnxa"
)
del list.tmp

benjib77
Posts: 2
Joined: 27 Aug 2012 03:40

Re: How to copy directories and files as empty files

#4 Post by benjib77 » 27 Aug 2012 04:38

Yeah! That's exactly what I need :) Works fine. Thx a lot!

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: How to copy directories and files as empty files

#5 Post by Ocalabob » 27 Aug 2012 20:08

The OP's problem has been solved by foxidrive but I would use
Robocopy in a batch file. Requires XP or better.

Code: Select all

@echo off
ROBOCOPY c:\source_folder c:\destination_folder /e /create


When using Robocopy if c:\destination_folder does not exist it will
be created plus the OP now has 9 more lines in his/her batch file to
perform other tasks. :)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to copy directories and files as empty files

#6 Post by Squashman » 27 Aug 2012 20:16

Ocalabob wrote:The OP's problem has been solved by foxidrive but I would use
Robocopy in a batch file. Requires XP or better.

Code: Select all

@echo off
ROBOCOPY c:\source_folder c:\destination_folder /e /create


When using Robocopy if c:\destination_folder does not exist it will
be created plus the OP now has 9 more lines in his/her batch file to
perform other tasks. :)

Or glass half full. They have a batch file that is 9 lines shorter! :D
But also remember that Robocopy is not installed by default on XP. Has to be installed from the Resource Kit. Plenty of places that I have worked at since XP came out and nobody installed the resource kit tools for XP on their installs by default.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to copy directories and files as empty files

#7 Post by foxidrive » 28 Aug 2012 02:06

That's useful Ocalabob :)

Post Reply