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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS batch file: How to copy sb-directories? 1

Status
Not open for further replies.

hotfusion

Technical User
Jan 20, 2001
755
GB
Gentlemen,
Firstly, DOS batch files aren't my stong point, so bear with me!

I have set up a batch file which can be executed from the desktop to automate the back-up a number of folders in various locations on the C: partition to another, safer location, for when I replace an image of C:, which I do fairly regularly. (Kids!!)

With most situations there is no problem - backing up the IE favorites is simple enough, as is the e-mail folder, along with a few others.

The problem I'm having is where a folder might have sub-directories, in this case the 'My Documents' folder.

The following shows a snippet of code, but I'm finding that any sub-directories seem to be ignored, and only files within the main folder are copied, not directories:

DELTREE /Y D:\BACKUPS\MYDOC1
MKDIR D:\BACKUPS\MYDOC1\
XCOPY C:\MYDOCU~1\ D:\BACKUPS\MYDOC1\

I'd appreciate any pointers as to why directories aren't being copied, and indeed if it is possible.
The second line seems to be unneeded in practice - I'd appreciate comments on this too.


Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
Hot Fusion
 
In a dos boxxcopy /? gives you the options.

/S will copy subdirectories apart from empty ones

/E copies them even if they are empty

/T creates the directory structure without copying anything. Does not create empty directories/subdirectories.
 
Thanks very much Zeitghost, adding the /E switch does what I wanted.
(Now why didn't I think of looking at the /? option??)

Still have an issue with this line:

MKDIR D:\BACKUPS\MYDOC1\

I get the message 'unable to create directory'. Removing the '/' off the end solves this (can't recall why I used it in the first place) but is this line even necessary? The directory seems to be created anyhow by the third line. Is this strictly safe, or should the second line be included for completeness?

Many thanks.

Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
My home page
 
On xcopy, don't forget to add /V to verify what you've copied. It takes a little longer but you won't notice it unless, like me you're running on a 25MHz box.
 
1)You are trying to create a null directory under \mydoc1\.
2)Xcopy will create any needed directories.
3)And why do a deltree in this case. A simple delete of the directory will accomplish what you want. It will also elimintat the need to create the directory again.


Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Thanks for the tip XWB - the '/V' switch might be a useful addition.

Ed, I used Deltree to completely remove the directory in preparation for recreating it anew, to ensure that everything was removed as in some folders to be backed up the sub directories may vary in structure from what was backed up previously. Am I correct in thinking the 'DEL' command is for files only?

Thanks for your comments.

Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
My home page
 
You are correct. I made the suggestion because the original post did not indicate that there were subs underneatrh.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Just to let you all know the suggested tips work a dream, and the multiple backups needed can now be performed at the click of a desktop icon.

Thankyou all for you input.

Regards, Andy.
**************************************
My pathetic attempts at learning HTML can be laughed at here:
My home page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top