Solved Search for file in root dir of drive

December 16, 2013 at 22:27:32
Specs: Windows 8.1 Pro x64, Intel i5 (3rd Gen) / 16Gb
Looking for a specific file in the list of drives possibly available to search from.

Looking for: InstallOS.cmd

Ive seen a few examples but I cannot get one to work correctly.
Using fsutil is not an option.

Will be located here for example: D:\Install.CMD
(D just being an example of the drive letter that it would be located in.)


See More: Search for file in root dir of drive

Report •


#1
December 16, 2013 at 23:49:15
✔ Best Answer
for %%Z in (c d) do (dir/b %%Z:\Install.CMD)

if they're hidden use /ah

=====================
M2 Golden-Triangle


Report •

#2
December 16, 2013 at 23:59:55
@echo off
set drive=
for %%a in (a,b,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 (
    >nul 2>&1 dir "%%a:\install.cmd"
    if not errorlevel 1 (
        if defined drive (
            echo more that one drive has "install.cmd" on it!!!!!!!!
            pause
            goto :eof
        )
        set drive=%%a:\
    )
)

if defined drive (
    echo drive "%drive%" is the only drive that contains "install.cmd"
) else (
    echo no drive containing "install.cmd" was found on this computer
    pause
    goto :eof
)
pause

message edited by whert


Report •

#3
December 17, 2013 at 00:31:50
Thanks whert but your solution was a bit much for my needs. I will work with M2's.

I am passing along a variable with this that is set in batchA to batchB.
This should function, will test.

for %%Z in (c d) do (dir/b CALL %%Z:\Install.CMD %FIRMWARE%)


Report •

Related Solutions

#4
December 17, 2013 at 06:39:25
This smells like something that'd be handled easier with relative paths.

How To Ask Questions The Smart Way


Report •

#5
December 17, 2013 at 08:51:23
M2, I tired your solution and I received: %%Z was unexpected at this time.
Running this in WinPE.

Report •

#6
December 17, 2013 at 09:01:10
Did you type it in, or use a script? M2's version is the script version.

How To Ask Questions The Smart Way


Report •

#7
December 17, 2013 at 16:54:05
I had typed it but I got it now. Also, threw me till I noticed you both only typed Install.cmd and not InstallOS.cmd. Anyways, It started the InstallOS.cmd

Only issue I am having now is that it tries to start InstallOS.cmd from every drive I have in the list. Originally C and D but i have C through Z which is creates a error/popup for each.

For now, the one posted by whert is being used, now if I can figure out how to slim it down :/

message edited by Phrey89


Report •

#8
December 17, 2013 at 17:52:59
Looking for: InstallOS.cmd

....

Will be located here for example: D:\Install.CMD

If you can't get it right how can we?


Report •

#9
December 17, 2013 at 19:10:52
lol - we only human and its not like I am complaining. Like I said I figured it out. Your scripting is nice, if a little long winded. ;)

Report •

#10
December 17, 2013 at 21:00:28
(Late-comer to this thread.) Maybe kindof-a-combo of M2's and whert's, like:

for %%a in (c d e) do %%a:\installos.cmd %firmware% 2>nul

not having tested, you may need this version:
(for %%a in (c d e) do %%a:\installos.cmd %firmware%) 2>nul

Presumably, if either the drive is not existant, or it does not have "installos.cmd" at its root, or if installOS itself trhows an error, then there will be no action taken. If you wanted a log, you could substitute a logfilename for "nul" and send both primary and/or error out to it.


Report •

#11
December 18, 2013 at 10:58:06
It works well nbrane, thanks.

Think this will work?

for %%p in (c d e) do if exist %%p:\logs SET LOGDIR=%%p:\Logs 2>nul
I've shorted the drives list for now but I use all the letters except a-b. I think that this line is throwing a output into installos.cmd
and at the end when I have it output to the logs file >>%logdir%\Final.log it doesn't output and tries to do it for ever drive ive listed.


Report •

#12
December 18, 2013 at 21:19:11
At this point, you should post your current, full script. It has probably mutated beyond any blind attempt at genetic sequencing without the full DNA. (In other words, I'm lost!)

Report •

#13
December 19, 2013 at 04:53:41
StartNet.cmd
---------
:: StartNet.CMD
:: Placed in System32 of WinPE
@ECHO OFF
:: Setup for InstallOS.cmd
wpeutil UpdateBootInfo
for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET DetectFirm=%%B
:: Note: delims is a TAB followed by a space.
if %DetectFirm%==0x1 SET FIRMWARE=BIOS
if %DetectFirm%==0x2 SET FIRMWARE=UEFI
:: Add script to detect files needed.
for %%p in (a b 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 %%p:\logs SET LOGDIR=%%p:\Logs 2>nul
for %%a in (a b 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 %%a:\installos.cmd %LOGDIR% %firmware% 2>nul
:EXIT

InstallOS.cmd
---------
:: InstallOS.CMD v1.3
:: Written by: Humphrey
::
:: Runs from Windows PE to create partitions, apply a Windows image file, and setup the boot record.
:: In this version, BIN and IMAGES need to be in the same folder as InstallOS.CMD
::
@ECHO OFF
:: SETUP
SetLocal EnableDelayedExpansion
CD /D %~dp0
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET NowT=%%A & FOR /F "TOKENS=*" %%A IN ('DATE/T') DO SET NowD=%%A
SET BIN=.\bin\& SET IMGDIR=!BIN!Images\
:MAIN
TITLE Humphreys OS Installer
:: Main Menu / OS Selection
ECHO.
ECHO. Select which Windows version to install.
ECHO.
ECHO. 1] Windows Vista
ECHO. 2] Windows 7
ECHO. 3] Windows 8
ECHO.
SET /P VER=What version to install?:
IF "!VER!"=="" CLS & GOTO :MAIN
SET SVER=!VER! & CLS
:ARCHSEL
:: Architecture Menu
ECHO.
ECHO. 1] x32 (x86)
ECHO.
ECHO. 2] x64
ECHO.
SET /P ARCHSEL=What architecture to install?:
IF "!ARCHSEL!"=="" CLS & GOTO :ARCHSEL
IF "!ARCHSEL!"=="1" (SET Arch=x86& CLS) else SET Arch=x64& CLS
:PARTMENU
:: Partitioning Menu
ECHO.
ECHO.!FIRMWARE! was detected on boot.
ECHO.
ECHO. 1] MBR BIOS
ECHO.
ECHO. 2] GPT uEFI
ECHO.
SET /P PARTITION=What parition scheme to use?:
IF "!PARTITION!"=="" CLS & GOTO :PARTMENU
IF "!PARTITION!"=="1" SET PART=MBR& SET BOOT=W:\Windows\System32\bcdboot W:\Windows /l en-us /s S: /f BIOS& CLS
IF "!PARTITION!"=="2" SET PART=GPT& SET BOOT=W:\Windows\System32\bcdboot W:\Windows /l en-us /s S: /f UEFI& CLS
GOTO :!SVER!
:1
:: WinVista
SET IMGFILE=\v
ECHO.
ECHO. Windows Vista (!ARCH!)
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Ultimate
ECHO.
SET /P EDI=What edition to install?:
IF "!EDI!"=="" CLS & GOTO :1
IF "!EDI!"=="1" SET IMGINDX=2& SET CHK= Windows Vista Home Basic& CLS & GOTO :CHK
IF "!EDI!"=="2" SET IMGINDX=3& SET CHK= Windows Vista Home Premium& CLS & GOTO :CHK
IF "!EDI!"=="3" SET IMGINDX=4& SET CHK= Windows Vista Ultimate& CLS & GOTO :CHK
CLS & GOTO :1
:2
:: Win7
SET IMGFILE=\7
ECHO.
ECHO. Windows 7 (!ARCH!)
ECHO.
ECHO. 1] Home Basic
ECHO. 2] Home Premium
ECHO. 3] Professional
ECHO. 4] Ultimate
ECHO.
SET /P EDI=What edition to install?:
IF "!EDI!"=="" CLS & GOTO :2
IF "!EDI!"=="1" SET IMGINDX=1& SET CHK= Windows 7 Home Basic& CLS & GOTO :CHK
IF "!EDI!"=="2" SET IMGINDX=2& SET CHK= Windows 7 Home Premium&& CLS & GOTO :CHK
IF "!EDI!"=="3" SET IMGINDX=3& SET CHK= Windows 7 Home Professional& CLS & GOTO :CHK
IF "!EDI!"=="4" SET IMGINDX=4& SET CHK= Windows 7 Ultimate& CLS & GOTO :CHK
:3
:: Win8.x
SET EDI=
ECHO.
ECHO. 1] Windows 8
ECHO.
ECHO. 2] Windows 8.1
ECHO.
SET /P EDI=What edition to install?:
IF "!EDI!"=="" CLS & GOTO :3
IF "!EDI!"=="1" SET IMGFILE=\8& SET CHK1=Windows 8& CLS & GOTO :4
IF "!EDI!"=="2" SET IMGFILE=\81& SET CHK1=Windows 8.1& CLS & GOTO :4
:4
:: Win8 Edition
SET EDI=
ECHO.
ECHO. !CHK1! (!ARCH!)
ECHO.
ECHO. 1] Core
ECHO.
ECHO. 2] Professional
ECHO.
SET /P EDI=What edition to install?:
IF "!EDI!"=="" CLS & GOTO :4
IF "!EDI!"=="1" SET IMGINDX=2 & SET CHK= Core& CLS & GOTO :CHK
IF "!EDI!"=="2" SET IMGINDX=1 & SET CHK= Professional& CLS & GOTO :CHK
:CHK
SET CONT=
:: Install OS Check
TITLE Install Check
ECHO.
ECHO.Start installation of: !CHK1!!CHK! (!ARCH!) [!PART!]
ECHO.
SET /P CONT=[Y]es / [N]o:
IF "!CONT!"=="" CLS & GOTO :CHK
IF /I "!CONT!"=="Y" CLS & GOTO :APPLYSETTINGS
IF /I "!CONT!"=="N" SET PARTITION=& SET PART=& SET ARCHSEL=& SET EDI=& SET ARCH=& SET IMGFILE=& SET IMGINDX=& SET VER=& CLS & GOTO :MAIN
CLS & GOTO :CHK
:APPLYSETTINGS
ECHO.
:: Applies image file and creates the partitions tables and boot settings.
DISKPART /S !BIN!!PART!.txt
DISM /APPLY-IMAGE /IMAGEFILE:!IMGDIR!!ARCH!!IMGFILE!!ARCH!.wim /INDEX:!IMGINDX! /APPLYDIR:W:\
!BOOT!
:LOG
:: Outputs log of completed install.
ECHO.Installed !CHK1!!CHK! !ARCH! on !NowD! @ !NowT! >>!LOGDIR!\Final.log
Start CMD


Report •

#14
December 19, 2013 at 20:53:45
You need to decide what to do if drive:\logs does not exist: either A) create the directory, or B) send log output into the ether (nul). Your code, as it stands, will only select the LAST drive that has \logs off its root, not necessarily the one that has installOS on it. I would recommend adding code to installOS (right after "CD /D %dp0") to this effect:

set logpath=%dp0\Logs
:: A option
if not exist %logpath% md %logpath%
set logOUT=%logpath%\Final.Log

::B option
if not exist %logpath% set logOUT=nul

the next-last line should reflect this substitution using %logOUT% instead of !logdir!\Final.Log


Report •

#15
December 19, 2013 at 21:34:16
"as it stands, will only select the LAST drive that has \logs off its root, not necessarily the one that has installOS on it."

And for now that is fine as I have this as a ISO, booting into VMware.

The ISO is seen as a unwrittable disk. Drive D:\ Which is where InstallOS.cmd is ran from. (No log dir here)
The WinPE (OS stored/ran from RAM) where things are writable, is usually Drive X:\ which is stored in ram. Which is where the logs should be writing to.

Plus, seeing as WinPE, will always have a Logs folder- what it has now should work. No? (I modified the boot.wim to include this Drive:/Logs folder.)

I have attached a picture. (Never mind, "Add a Screen Capture" is weird. Unless it worked and I just do not see it.)

http://i.imgur.com/rjHmNHr.png


Report •

Ask Question