Batch: Find directory on local drives and prompt user

Discussion in 'Scripting' started by slatan, Feb 6, 2014.

  1. slatan

    slatan MDL Novice

    Jan 18, 2011
    4
    0
    0
    #1 slatan, Feb 6, 2014
    Last edited by a moderator: Apr 20, 2017
    I'd like to incorporate a chunk into a batch file that searches local drives for a directory, let's say \Temp. If the directory only exists on only one drive, then set a variable, like %temploc%, to that drive. If the directory exists on more than one drive, display the drives that contain \Temp and prompt the user to select which directory to use and set the variable to their selection.

    I have this snippet already:

    Code:
    FOR %%a IN ( C D E F G H I J ) DO IF EXIST %%a:\temp\NUL ECHO Temp directory found on %%a
    which searches the local drives (C through J) and reports the drives that contain the \Temp directory if that helps.

    Can anybody help with the rest? It seems like it should be pretty straight-forward, but I'm not having much luck.
     
  2. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    84
    10
    #2 Dos_Probie, Feb 6, 2014
    Last edited by a moderator: Apr 20, 2017
    This should get you started..
    untested, DP:biggrin:

    Code:
    @echo off & setLocal EnableDELAYedeXpansion
    title, [ Find TEMP Directory on All Drives ]
    for %%d in (c d e f g h i j) do (
      if exist %%d: (for /f "tokens=* delims= " %%a in ('dir/b/s %%d:\temp 2^>nul') do (
          Echo Temp directory found on: "%%a")
      )
    )
    pause