Computing.Net > Forums > Programming > BATch file -- Delay after deltree

BATch file -- Delay after deltree

Reply to Message Icon

Original Message
Name: MoMoShiKu
Date: January 23, 2006 at 19:59:13 Pacific
Subject: BATch file -- Delay after deltree
OS: Windows XP Pro
CPU/Ram: P4 1.6Ghz, 512Mb RAM
Comment:

Hi there,

I got a ugent question here.

I am using a .bat file to do the backups. I want to make sure the destination folder is clean before I use "xcopy" command to copy the files into it.

In my code, I use "deltree" to empty the destination folder, and then xcopy the files into it.

Part of my code I got:
deltree /Y "%Dest%\%foldername%"
md "%Dest%\%foldername%\"
for /f "tokens=*" %%a in (path.txt) do call :GetPath "%%a

And then it start xcopying the files in GetPath.

The problem is, "xcopy" dosen't seems to wait until the "deltree" finishes. Instead, its deleting files and xcopying the files at the same time, and end up I got a funny backup.

Does anyone know how to delay the batch file until the deltree finishes? any idea?

Thanks,


Report Offensive Message For Removal


Response Number 1
Name: MoMoShiKu
Date: January 23, 2006 at 21:58:13 Pacific
Reply: (edit)

Hi everyone,

sorry I forgot to metion one thing, I didn't use xcopy to copy the file to destination folder straight away. I xcopy it, and I "move" it to the destination.

I think the problem now is that.. the deltree doesn't delete everything somehow, and when it comes to "move", the "move" command can not overwrite those already there folder.

So why is my "deltree" dosen't delete everything but leave some empty folders and sub-folders?? ...lol

HELP plz!


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: January 23, 2006 at 22:23:43 Pacific
Reply: (edit)

momo-chan,

I doubt very much that the xcopy is starting before the deltree finishes. That's not the way a bat works.

I think you have a different problem.

But if it makes you sleep better, you can add a conditional pause, like this:

deltree
md test
if errorlevel 1 pause

If the md fails becaise the directory already exists, it will pause.

[Strangely, a deltree fail does NOT set errorlevel 1; no idea why.]



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 3
Name: IVO
Date: January 24, 2006 at 02:08:56 Pacific
Reply: (edit)

In Windows XP/2K use RD instead of DelTree

RD /S /Q "%Dest%\%foldername%"

Try and your batch would work fine.


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: January 24, 2006 at 02:59:04 Pacific
Reply: (edit)

Hi IVO,

Yeah, not obvious what dektree's problem is; but I guess it has one.



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 5
Name: IVO
Date: January 24, 2006 at 06:17:02 Pacific
Reply: (edit)

Hi M2,

I do not understand in deep the problem that originated this thread as what posted should not happen at all, anyway about the commands you posted

1) the ErrorLevel always refers just to the previous command so it reports the execution of the MD *NOT* how Deltree ended; the only exception is related to those commands not setting the error code, e.g. Echo.

2) sometime a DOS kernel native command like DelTree fails to report the correct error code under Win XP/2K.

However the core problem remains quite obscure to me.


Report Offensive Follow Up For Removal


Response Number 6
Name: IVO
Date: January 24, 2006 at 06:20:25 Pacific
Reply: (edit)

Sorry M2, I missed you just wanted to check the MD exit code, but my second note is still valid.


Report Offensive Follow Up For Removal

Response Number 7
Name: Mechanix2Go
Date: January 24, 2006 at 06:59:35 Pacific
Reply: (edit)

Hi IVO,

Yes, the MD will set 1 if the directory creation has failed. Which it will if the deltree has failed.

As you say, there's more to this.

Why is deltree sometimes failing?

Maybe it needs to be preceded with:

attrib /s -r -s -h

I don't get the point of copy then move.

momo,

try- putting this before the deltree:

attrib /s /d -s -h -r [your old stuff]



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 8
Name: MoMoShiKu
Date: January 24, 2006 at 14:04:56 Pacific
Reply: (edit)

Thanks alot for all your help! I really appreciate it.

I think I might found out the problems now, but let me explain the whole thing...

1. The reason I do "xcopy" and then "move", is because of:
At the first I got:
* xcopy "%Path%" "%Dest%\%foldername%\%Path:~3%\" /e /r /v /h /k /y

and it gave me an "Insufficient Memory" error. I think it happens when I got a too long 'path name' + 'file name'??? So I xcopy it into a shorter destination (a root folder), and then "move" them to the real %dest% and it seems working fine.


2. In order to make sure the backup is the latest copy, I put a
* deltree /Y "%Dest%\%foldername%"
before I copying the files.


3. Then the problem was, the "deltree" doesn't delete everything, and the "move" doesn't want to overwirte those folders that didn't deleted by "deltree"


4. Just now I found out, if I don't use '/k' in the "xcopy", and use '/g' instead, the deltree successed. so I will have:

deltree /Y "%Dest%\%foldername%"
md "%Dest%\%foldername%\"

xcopy "%Path%" "c:\CurrentBk\%Path:~3%\" /e /r /v /h /g /y

move /Y "c:\CurrentBk\%Path:~3%" "%Dest%\%foldername%\"

deltree /Y "c:\CurrentBK\"

So I think it must be a attributes problem? coz the only folder that deltree wouldn't delete was the 'Favorites'


5. A side question, why is that, after i run a BAT file, the standard DOS command won't work in CMD? (eg. xcopy, move..) I have to copy the "xcopy.exe" and "deltree.exe" into my working forlder to make it work?


* Thanks again for all your help, and sorry about my bad English, im tring hard with it.. lol



Report Offensive Follow Up For Removal

Response Number 9
Name: IVO
Date: January 24, 2006 at 15:35:50 Pacific
Reply: (edit)

As XCopy and DelTree are external command, i.e. true executable as the .exe extension showes, they must be stored in folders declared in the Path variable or in the current one.

Copy, Move and MD are internal ones instead, i.e. they are wired in CMD.exe so they are always accesible.

By the way there is no DOS in Win XP, it is a NT kernel system and what you see is actually an emulator, the NTVDM (NT Virtual DOS Machine).


Report Offensive Follow Up For Removal

Response Number 10
Name: MoMoShiKu
Date: January 24, 2006 at 16:06:38 Pacific
Reply: (edit)

Thanks IVO,

I just tried with the RD command, and it just works fine without changing another code!!

So is RD a internal command aswell? and is it can only be used in Win XP and 2000?

thanks =)


Report Offensive Follow Up For Removal

Response Number 11
Name: Mechanix2Go
Date: January 24, 2006 at 22:24:13 Pacific
Reply: (edit)

Hi momo,

[1] As far as I know there is no /g in XCOPY.

[2] XCOPY /k preserves the attribs; but that should not matter.

[3] As indicated by IVO, the failure of XCOPY [or other external] to run says that your PATH is getting lost.

To see if this is a problem, try putting these into your batch:

Immediately after the @echo off, put:

echo %PATH% > pathchek

then as a last line put:

echo %PATH% >> pathchek

then look at the pathchek file to see if your PATH is getting changed.

I don't understand your use of the %PATH:~3%

[4] I have never gotten an 'out of memory' error with XCOPY. That would seem to indicate a corrupt XCOPY.exe or a damaged logical disk structure.

[5] You can avoid over length paths [and make your code much cleaner] by using SUBST.

If you have a path like:

c:\temp\-\some\long\road

you can:

subst x: c:\temp\-\some\long\road


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 12
Name: IVO
Date: January 25, 2006 at 02:34:35 Pacific
Reply: (edit)

Yes, RD (short code for RmDir i.e. Remove Directory) is an internal command belonging to the native file system manipulation group.

Internal commands are built-in functions coded inside the command interpreter (CMD.exe for the NT family, NT/2K/XP/2K3, Command.com for the DOS line, 9X/ME), so you can't use RD with a DOS kernel system as its shell (Command.com) lacks it.

Internal vs external commands is a legacy from the original 16 bit DOS where to keep the size of the interpreter was as low as possible was mandatory due to the 640 KB conventional memory wall.

You have always to keep in your mind that scripting in Win XP/2K is actually coding NT NOT DOS batch.


Report Offensive Follow Up For Removal

Response Number 13
Name: MoMoShiKu
Date: January 26, 2006 at 01:42:48 Pacific
Reply: (edit)

Thanks for your explanation IVO, now I understand =)


Report Offensive Follow Up For Removal

Response Number 14
Name: MoMoShiKu
Date: January 26, 2006 at 03:01:47 Pacific
Reply: (edit)

Hi M2, thanks for your help.

To reply your message:

[1] Yes, there is a /G swich in XCOPY. Try xcopy /? in CMD. It says...
/G Allows the copying of encrypted files to destination that does not support encryption.

[2] The reason I use %path:~3%, is because, the %path% is a path in the form "x:\dir\dir.." , and i only want the part after x:\ (3 chars)

[3] I checked (echo) all the %path% before it execute XCOPY, and they seems alright.

My XCOPY runs for a while and STOPS with an "Insufficient Memory" error. Also, I think it always stop at the same place.

The only xcopy path I had that always stop at is:

xcopy "C:\Documents and Settings\user\My Documents" "C:\Documents and Settings\user\Local Settings\Application Data\Microsoft\CD Burning" /e /r /v /h /k

So I guess if the path length is not the case, then must be something within my files.

Also, here is a discussion I found..
it says the full directory path starting with the drive letter plus the file name can not longer than 254 characters.

http://www.blogdom.org/archives/000792.php

[4] Thanks for the SUBST command, I think that was the command I am looking for all the time.. lol

[5] If you are interested.. I can post my code here! It got some funny setup. It reads a list of backup path from "path.txt", and copy the files in those path into the destination in "dest.txt".

I may post it tomorrow, the batch is in my office.

thanks, =)


Report Offensive Follow Up For Removal

Response Number 15
Name: Mechanix2Go
Date: January 26, 2006 at 03:40:24 Pacific
Reply: (edit)

Hi momo,

[1] I did xcopy /? before I wrote that and did not see /g. Then I tried to xcopy something with /g and got:

C:\temp\->xcopy /g . zz\
Invalid switch - /g

So either XP XCOPY is very different from w2k [and all thye others I have used], which I doubt, or yours is corrupted. Which would account for the alleged 'mem error'.

I just sent you w2k xcopy. Rename yours and try mine.

Please carefully reread [3] in my #11 and post EXACT pathchek.


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: BATch file -- Delay after deltree

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes Today.
Discuss in The Lounge