Jump to content

Batch File Problem


Recommended Posts

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?

Link to comment
Share on other sites


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.

Link to comment
Share on other sites

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

Edited by Delprat
Link to comment
Share on other sites

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

Edited by RaveRod
Link to comment
Share on other sites

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.

Edited by RaveRod
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Edited by RaveRod
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 3 weeks later...
Guest Denney

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

Link to comment
Share on other sites

Guest Denney

: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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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:

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...