MSFN Forum: Batch File Problem - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch File Problem XCOPY and ECHO commands Rate Topic: -----

#1 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

  Posted 21 March 2006 - 02:46 PM

Here's one for you "pros".

Current code:
SET UUCDDRIVE=nocd
FOR %%i IN (c d e f g h i j k l m n o p q r s t u v w x y z) DO IF EXIST %%i:\UCD SET UUCDDRIVE=%%i:

IF NOT "%UUCDDRIVE%"=="nocd" (
	IF EXIST %UUCDDRIVE%\ALL XCOPY %UUCDDRIVE%\ALL %SystemDrive%\UOS /E /C /I /Q /H /Y
	IF EXIST %UUCDDRIVE%\PDC XCOPY %UUCDDRIVE%\PDC %SystemDrive%\UOS /E /C /I /Q /H /Y
) ELSE (
	ECHO.
	ECHO Ultimate Update CD not found.
	ECHO.
	PAUSE
)

ECHO is turned OFF at the start of this script. During execution, the XCOPY commands return the error:
Current directory doesn't exist.

And they don't copy the files over.

Here's the thing, if I add an "ECHO ON" statement before the "IF" statement or if I don't turn ECHO off at all, it works flawlessly. I tried using CMDOW to hide the window during the "ECHO ON" time and it, again, ceased to work.

It's got me stumped how an "XCOPY" command could require ECHO to be ON for it to work. Any thoughts?


#2 User is offline   Noise 

  • Windows Guru
  • PipPipPip
  • Group: Members
  • Posts: 425
  • Joined: 27-February 04

Posted 21 March 2006 - 02:54 PM

Surround your directory entries in quotes:
IF EXIST "%UUCDDRIVE%\ALL" XCOPY "%UUCDDRIVE%\ALL" "%SystemDrive%\UOS" /E /C /I /Q /H /Y

That's may not be the problem, but it's good practice. Try turning echo on right before the "if not" statement to debug.

#3 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 21 March 2006 - 03:01 PM

You've found the Ultimate Bug :P

This script will not show that error :
SET UUCDDRIVE=
FOR %%i IN (c d e f g h i j k l m n o p q r s t u v w x y z) DO IF EXIST %%i:\UCD SET UUCDDRIVE=%%i:

IF NOT DEFINED UUCDDRIVE (
	ECHO.
	ECHO Ultimate Update CD not found.
	ECHO.
	PAUSE
	GOTO :THERE
)
CHDIR /D %SystemDrive%\
MKDIR UOS
CHDIR UOS
XCOPY %UUCDDRIVE%\ALL . /E /C /I /Q /H /Y
IF EXIST %UUCDDRIVE%\PDC XCOPY %UUCDDRIVE%\PDC . /E /C /I /Q /H /Y

:THERE

This post has been edited by Delprat: 21 March 2006 - 03:03 PM


#4 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

Posted 21 March 2006 - 03:10 PM

Ok, so maybe you've fixed it but I'm more of the sorta person who wants to know WHY it doesn't work rather than what I have to do to fix it.

Why was I getting that error?

Oh, btw, the %SystemDrive%\UOS directory already exists on the hard drive when I copy the stuff over so the "MKDIR" command is pointless.

Also, thanks for the quick response. :P

This post has been edited by RaveRod: 21 March 2006 - 03:14 PM


#5 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

Posted 21 March 2006 - 03:31 PM

Ok, now that's weird.

Changed my code to a mutation of yours for testing:
SET UUCDDRIVE=nocd
FOR %%i IN (c d e f g h i j k l m n o p q r s t u v w x y z) DO IF EXIST %%i:\UCD SET UUCDDRIVE=%%i:

IF "%UUCDDRIVE%"=="nocd" GOTO NOTFOUND

CHDIR /D %SystemDrive%\UOS\
IF EXIST %UUCDDRIVE%\ALL XCOPY %UUCDDRIVE%\ALL %SystemDrive%\UOS /E /C /I /Q /H /Y
IF EXIST %UUCDDRIVE%\PDC XCOPY %UUCDDRIVE%\PDC . /E /C /I /Q /H /Y
PAUSE
GOTO MORE

:NOTFOUND
ECHO.
ECHO Ultimate Update CD not found.
ECHO.
PAUSE

:MORE

That works perfectly. Note that one IF statement copied to "%SystemDrive%\UOS" and the other copies to ".". Both the IF statements works... :yes:

It seems to pivot on that CHDIR command. Without it, the script dies. That I can't explain and I guess I only have Microsoft to thank for that error.

Thanks for the fix Delprat. Much appreciated after my 4 hours of figuring nothing out.... :wacko:

Edit: Went back to my ORIGINAL code and added the "CHDIR /D %SystemDrive%\UOS\" command just before the "IF EXIST" command and it works perfectly! God damnit, all that wasted time when it was that simple! Anyway, thanks again for the help. Much appreciated.

This post has been edited by RaveRod: 21 March 2006 - 03:42 PM


#6 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 22 March 2006 - 03:07 AM

View PostRaveRod, on Mar 21 2006, 11:10 PM, said:

Why was I getting that error?


That's the hard question...

[edit: lots of stupid ideas based on wrong suppositions... ]

This post has been edited by Delprat: 11 April 2006 - 08:33 AM


#7 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

Posted 23 March 2006 - 09:32 AM

Thanks for that code Delprat. Didn't even think about doing the for loop like that.

Has the hidden advantage of letting me use 2 update cds in different drives without prompting.

Thanks.

#8 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 23 March 2006 - 10:31 AM

View PostRaveRod, on Mar 23 2006, 05:32 PM, said:

Has the hidden advantage of letting me use 2 update cds in different drives without prompting.


:no:
The GOTO will break the loop after the first CD.

#9 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

Posted 23 March 2006 - 11:21 AM

Yeah I took that GOTO command out...

Didn't mention that.

Replaced it with a SET command and then after the loop has finished, I check if the variable is defined. If it is, I THEN use the GOTO command.

This post has been edited by RaveRod: 23 March 2006 - 11:22 AM


#10 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,249
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 March 2006 - 07:14 AM

use CALL instead of GOTO and it will return.
at the end of the called section send it to the EOF and it will return to the loop.

...
...
...

Call :UUCDFOUND
)

:UUCDFOUND
commandx
commandx
goto EOF

...
...
...
...
...

:EOF


#11 Guest_Denney_*

  • Group: Guests

Posted 11 April 2006 - 08:25 AM

I FINALLY FIGURED IT OUT!!!

At that point during setup, the "current directory" for the "cmd" prompt is "D:\$OEM$".

The problem is, when you remove the CD and put another one in, the "$OEM$" directory doesn't exist so when you go to perform any operations, the error will come up.

So after all of that, the "CHDIR" command IS required for the script to work properly when performing the FOR loop. It only just occured to me today what the problem was... :S

#12 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 11 April 2006 - 08:34 AM

that issue is from good old dos...

next time, i won't suppose anything about your knowledge before making suppositions :lol:

This post has been edited by Delprat: 11 April 2006 - 08:35 AM


#13 Guest_Denney_*

  • Group: Guests

Posted 11 April 2006 - 08:49 AM

:P I've learnt never to assume anything about anyone around here. Especially when they've been around for awhile.

I now have another couple of problems but they're with my coding and can be figured out pretty easily. Thankfully that biggest problem has now been sorted out.

#14 User is offline   Denney 

  • *shrug*
  • PipPipPipPip
  • Group: Members
  • Posts: 685
  • Joined: 11-September 03

Posted 12 April 2006 - 04:25 AM

Another quick update...

In some circumstances, adding the CHDIR %SomeDir% command won't work if it's on another drive. You need to add the /D switch to change the current drive as well as the current directory.

Strange quirk in that it works sometimes but not others. So, the FINAL script is:

CLS
ECHO Please insert an Ultimate Update CD now.
PAUSE

ECHO ON
CD /D %SystemDrive%
CMDOW.EXE @ /HID
SET UUCDDRIVE=
FOR %%i IN (c d e f g h i j k l m n o p q r s t u v w x y z) DO IF EXIST %%i:\UUCD.cmd SET UUCDDRIVE=%%i:

IF DEFINED UUCDDRIVE (
	START /WAIT %UUCDDRIVE%\UUCD.cmd %UUCDDRIVE% %ADMINUSER%
)
CMDOW.EXE @ /VIS
ECHO OFF

CLS
SET /P MORE="Do you have anymore Ultimate Update CD's (y/n)? "
IF "%MORE%" == "y" GOTO STARTSEARCH


#15 User is offline   Delprat 

  • Poll: Why are you reading this ?
  • PipPipPip
  • Group: Members
  • Posts: 481
  • Joined: 18-May 05

Posted 12 April 2006 - 08:50 AM

View PostDenney, on Apr 12 2006, 12:25 PM, said:

In some circumstances, adding the CHDIR %SomeDir% command won't work if it's on another drive. You need to add the /D switch to change the current drive as well as the current directory.

Try "CHDIR /?" in the console :rolleyes:

View PostDenney, on Apr 12 2006, 12:25 PM, said:

START /WAIT %UUCDDRIVE%\UUCD.cmd %UUCDDRIVE% %ADMINUSER%

Remove the first parameter (%UUCDDRIVE%), and in UUCD.cmd use %~d0 (instead of %1) to refer to the drive the UUCD.cmd file is in

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy