Jump to content

Recommended Posts

Posted

I found what was causing the problem this line now makes it worked

I did not notice there was no space between the SETVARS and IF

:SETVARS IF EXIST %1 (IF EXIST %2 (

This was causing the error.

:SETVARSIF EXIST %1 (IF EXIST %2 (

When I pasted the original code it was 1 very long line

@ECHO OFFFOR %%? 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 (	CALL :SETVARS %%?:\NTLDR %%?:\boot.ini ||GOTO :ABORT):ABORTPAUSE &GOTO :EOF:SETVARSIF EXIST %1 (IF EXIST %2 (	ECHO/&ECHO/%1 size is %~z1 bytes&ECHO/%2 size is %~z2 bytes&ECHO/&&EXIT/B 1))EXIT/B 0


Posted
@echo off
setlocal enableextensions enabledelayedexpansion
for %%J 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 (
set tags=%%J:\boot.ini %%J:\ntldr
for %%I in (!tags!) do (
if exist "%%I" (
set %%~nI=%%J
Set %%~nIz=%%~zI
)
)
if "!boot!" NEQ "" iF "!ntldr!" NEQ "" goto finished
)

:finished
echo.
echo.
echo ntldr location is %ntldr%
echo boot.ini location is %boot%
echo.
echo Size of ntldr is %ntldrz%
echo Size of boot.ini is %bootz%

Posted

@ gunsmokingman

Yes that's line I told you was wrong, however, as in my example, the label is on a different line to the following commands.

@ IcemanND

Using nested for loops is not particularly good practice, delayed expansion can also be troublesome when using unknown filenames. Your code will also continue to search all letters in the loop once the matches have already been found. Using the filename without extension however was a good idea, even though for the required output, creating variables and using setlocal wasn't necessary.

Posted

@Yzowl - Actually it will stop once the if statement is true. Now if you were going to do this for a number of files or unknown files this would not be a good solution. But then if I was doing I'd probably use a vbscript and WMI.

Using setlocal depands upon the configuration of your system. some of my systems need it some don't depending upon how I've got it configured.

Posted

by the way, it seems almost completely not needed.

I mean:

I'm trying to install Grub in unattended setup. My script replaces ntldr with grub. However, I want to check the size of ntldr with a script.

Since the idea is to replace ntldr with grldr (not grub, that won't work), most probably following this idea:

http://www.911cd.net/forums//index.php?showtopic=18045

the ntldr to be replaced must be the one the machine usually boots from, which is 99,9999% in First Active Partition of First Harddisk (read C:\).

And this also explains why the original script has drive letters the "wrong" way....

... and the way it works, "overwriting" previous positive finds in other partitions

While I was thinking about it, I happened to produce these few lines:


for /f "tokens=3 delims= " %%A in ('Dir /A C:\ntldr ^| FINDSTR /I "ntldr"') DO (
echo ntldr size is %%A
REM whatever else
)

That effectively does the work without even needing an IF EXIST, as if the Dir command fails to find the file, feeds to FINDSTR an empty line, and the FOR loop is not executed.

Just change the C:\ntldr and ntldr with another string or with a variable to put it in a loop or called subroutine.....

jaclaz

Posted (edited)

Absolutely, right, Jaclaz. The check file size is not needed. However, I once reinstalled XP and it automatically changed my primary partition to an extended partition (it had 8 mb unpartitioned space before my first partition - I couldn't get rid of it using XP setup. Only way to get rid of it was to delete all my partition, but I didn't want to delete D: and E: since they both had data). So my ntldr and boot.ini ended up on D: while XP was on C:\.

What this means is that if you want to reinstall on C: when D: and E: are already present, don't delete C: and then create a new partition. Just install on C: and let it format.

It baffled me until I figured out what happened. So, I at least need to make sure that ntldr and boot.ini ended up in the right place.

The size check is not needed but gives you the assurance it's the right size...

What the heck... I learned something new from all this... I'll post a screenshot later of the error I'm getting (the " c:\ntldr" error).

Delprat should also know that his script about right-click installing fonts didn't work on my machine but it did on Windows 2000 I tested, so I have something wrong with my installation source. It's XP SP2 with Ryan VM packs.

Edited by spacesurfer
Posted

Yzowl and jaclaz, this is the error I get with Yzowl's script using mountvol. I modified the script a bit for my unattended to look for win51 and drivers.tag:

REM NEW SEARCH FOR CD-ROM DRIVE
REM -----------------------
for /f "delims=\" %%? in ('mountvol^|find ":\"') do dir/b/-d %%?\WIN51 &&SET CDDRIVE=%%?
ECHO.
GOTO DRVPATH

REM SEARCH FOR DRIVERS PATH
REM -----------------------
:DRVPATH
SET DRVPATH=%CDDRIVE%
for /f "delims=\" %%? in ('mountvol^|find ":\"') do dir /b /AS /-d %%?\DRIVERS\DRIVERS.TAG &&SET DRVPATH=%%?
ECHO.
goto STARTSETUP

Here are the screens that show the extra spaces:

This one shows the spaces before the drive letter assignment and after the dir command:

post-25917-1157679934_thumb.png

This one shows the spaces in the echo command:

post-25917-1157679945_thumb.png

And this one results in an error when I try to copy tweak.cmd to %systemroot%:

post-25917-1157679956_thumb.png

Any ideas on what can be causing this?

I probably will just have to use the for %%x in (c d e f g ....) and do the loop de loop thing.

Posted (edited)
Yzowl and jaclaz, this is the error I get with Yzowl's script using mountvol. I modified the script a bit for my unattended to look for win51 and drivers.tag:

<snip>

Point of note

This is not my script 'modified a bit', in fact the only bit that really bears any resemblence is:

%%? in ('mountvol^|find ":\"') do

<Re-Edit>

Here is one way of doing it, which has been simplified and may therefore be easier to understand

@ECHO OFF &SETLOCAL ENABLEEXTENSIONS

SET "DCT=DRIVERS" &SET "FIL=DRIVERS.TAG"

FOR /F %%? IN ('MOUNTVOL^|FIND ":\"^|FIND /V "A:\"') DO (IF EXIST %%?WIN51 (

IF EXIST %%?%DCT%\%FIL% (SET DRVPATH=%%?%DCT%)))

IF DEFINED DRVPATH (ECHO/%DRVPATH%) ELSE (ECHO/TAGFILE NOT FOUND)

ENDLOCAL &GOTO :EOF

You can remove the red text after testing if you so wish

</Re-Edit>

Edited by Yzöwl

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