Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copying a directory tree using a dos bat file

Status
Not open for further replies.

davidrobin

Programmer
Aug 17, 2000
50
0
0
GB
I have a dos bat file and want to copy a directory tree from one drive to another.
copy and xcopy only copy files and not any folder hierarchy (underlying folders).

What is the command for copying all files AND folders in a directory?

David
Visual Basic 6 Ent
 
xcopy /s /e /v /y /h Source Destination

/s Copies directories and subdirectories except empty ones.
/e Copies directories and subdirectories, including empty ones.
/v Verifies each new file.
/y Suppresses prompting to confirm you want to overwrite an existing destination file.
/h Copies hidden and system files also.

xcopy /? shows all of this.
 
Do you happen to know how to delete a folder and all its contents including nested directories.

I used to use deltree but XP does not recognise that.
Using del /? doesn't give me any extra info.

David
Visual Basic 6 Ent
 
You can use the RD command. with a few switches.
For example, the following command deletes the C:\BLAH directory and all subdirectories WITHOUT ANY WARNING:

RD C:\BLAH /S /Q

Use this command with caution! One slip-up and you could accidentally delete important files from your hard drive.

Hope this helps.
 
As PalmTest pointed out, XCOPY will copy all subdirectories if the /E option is used.

Also, you could use ROBOCOPY, which is not included with Windows by default. It is part of the Windows Server 2003 Resource Kit, which can be downloaded from Microsoft's web site at
ROBOCOPY is a command line utility with a LOT of options. There is a program called 'CopyRite XP' which is a graphical front-end which can help you manage all the options, and generate the appropriate command to run ROBOCOPY.

- James.


My memory is not as good as it should be, and neither is my memory.

I have forgotten more than I can remember
 
thanks for your help.

I shall endeavour to remember the /? switch for getting a little more information before posting.

David
Visual Basic 6 Ent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top