If you often use the CMD prompt and have to constantly navigate
to complex folder paths, CCD.cmd will make your life easier.
Dean Wells, MSEtechnology,
has scripted the ccd.cmd, which has the following help (CCD /?)
syntax:
ERROR - Nothing to do, help switch supplied ... syntax as follows -
CCD [any number or sequence of directory path components] [/R]
... /R causes the drive index to be rebuilt
e.g. -
CCD istrator applic data
... C:\Documents and Settings\Administrator\Application Data
CCD D: /r
... Causes the index for drive D to be rebuilt
NOTE - Drive specifiers must be the first argument suppliedOn first use, I built an index for each of
my drives:
CCD C: /r
CCD D: /r
Now, after opening a CMD prompt, I can navigate to the
TIP4700 folder
by typing:
C:\>ccd tip4700
STATUS - Multiple hits found as follows, using primary match ...
C:\InetPub\WWWRoot\SUBJ\TIP4700
C:\InetPub\WWWRoot\SUBJ\TIP4700\_vti_cnf
Type POPD to return to previous working directory
C:\InetPub\WWWRoot\SUBJ\TIP4700>
To return to the previous folder, type
popd.
To navigate to D:\WebCompiler\JSITTARH\SUBJ\TIP4700, I type ccd d: tip4700:
Type POPD to return to previous working directory
D:\WebCompiler\JSITTARH\SUBJ\TIP4700>
CCD.cmd contains:
:: Cute CD - Dean Wells, MSEtechnology - January 2002
@echo off
:: Check and redefine arguments
set SYNTAXERR=yes
set TMPSW=%*
if not defined TMPSW (
echo.
set ERROR=No arguments supplied, syntax as follows -
call :ERROR
goto :END
)
set SW=%TMPSW:"=%
if "%SW%"=="/?" (
echo.
set ERROR=Nothing to do, help switch supplied ... syntax as follows -
call :ERROR
goto :END
)
if not defined SW (
echo.
set ERROR=No arguments supplied, syntax as follows -
call :ERROR
goto :END
)
if not defined TMPSW (
echo.
set ERROR=No arguments supplied, syntax as follows -
call :ERROR
goto :END
)
set TMPDIR=%SW: /R=%
set DIR=%TMPDIR: /r=%
:: Prepare remaining environment, temporary files and the index
if "%DIR:~1,1%"==":" (
set DRIVE=%DIR:~0,1%
) else (
set DRIVE=%CD:~0,1%
)
:: Set the index file location
set INDEX=%TEMP%\%DRIVE%colon.ccd.index
:: Check for forced rebuild switch only
if /i "%SW%"=="/R" (
set REBUILD=yes
set REBUILDONLY=yes
)
:: Check for forced rebuild switch amongst other arguments
if not "%DIR%"=="%SW%" (
set REBUILD=yes
)
:: Check for absence of existing drive index
if not exist %INDEX% (
set REBUILD=yes
)
:: Convert case of drive letter (display purposes only)
for %%c 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 /i %DRIVE%==%%c set DRIVE=%%c
:: Check for drive validity
if not exist %DRIVE%: (
echo.
set ERROR=Drive specifier was invalid - %DRIVE%
call :ERROR
goto :END
)
:: Check for root argument only
if "%DIR%"=="\" (
set SPECIALCASE=yes
)
:: Check for drive letter only
if /i "%DIR:~0,3%"=="%DRIVE%:" (
if "%REBUILD%"=="yes" (
set REBUILDONLY=yes
) else (
echo.
set ERROR=Drive only specified, root of drive %DRIVE% assumed
set SYNTAXERR=no
call :ERROR
echo.
set SPECIALCASE=yes
)
)
:: Check for drive letter plus root only
if /i "%DIR:~0,4%"=="%DRIVE%:\" (
set SPECIALCASE=yes
)
:: Rebuild index if necessary or requested
if "%REBUILD%"=="yes" (
del %INDEX% 2>nul
echo.
echo STATUS - Building new directory index for drive %DRIVE% - Wait ...
dir %DRIVE%:\ /s /ad /b >%INDEX%
echo.
echo Completed!
)
:: Terminate if index rebuild was only argument supplied
if "%REBUILDONLY%"=="yes" goto :END
:: Check for special case target directory
if "%SPECIALCASE%"=="yes" (
set DIR=%DRIVE%: goto :SPECIALCASE
)
:: Check validity of existing index
if not exist %INDEX% (
echo.
set ERROR=The directory index for drive %DRIVE% could not be located
set SYNTAXERR=no
call :ERROR
goto :END
)
:: Create temporary index files
copy %INDEX% %INDEX%.src /y 1>nul 2>&1
if not exist %INDEX%.src (
echo.
set ERROR=The temporary index for drive %DRIVE% could not be created
set SYNTAXERR=no
call :ERROR
goto :END
)
:: Begin search for directory path strings supplied
for %%s in (%DIR%) do (
copy %INDEX%.src %INDEX%.tgt /y 1>nul 2>&1
type %INDEX%.tgt | find /i "%%s" >%INDEX%.src
)
:: Check for existence of temporary index files
if not exist %INDEX%.src (
echo.
set ERROR=Unable to read necessary temporary files
set SYNTAXERR=no
call :ERROR
goto :END
)
:: Set the target directory
set /p DIR=<%INDEX%.src
:: Count the number of hits and react accordingly
for /f %%c in ('type %INDEX%.src ^|find /c /v "#$VeRyUnLiKeLyToOcCuR$#"') do set COUNT=%%c
if %COUNT%==0 (
echo.
set ERROR=No directories found on drive %DRIVE% matching %DIR%, try using /R switch
call :ERROR
goto :END
)
if %COUNT% GTR 1 IF %COUNT% LSS 21 (
echo.
echo STATUS - Multiple hits found as follows, using primary match ...
echo.
type %INDEX%.src
) else (
echo.
set ERROR=Too many hits to display, using primary match ...
set SYNTAXERR=no
call :ERROR
echo.
)
:: Ready to change to new target working directory
:SPECIALCASE
pushd "%DIR%"
if not defined ERROR echo.
echo Type POPD to return to previous working directory
goto :END
:ERROR
echo ERROR - %ERROR%
if not "%SYNTAXERR%"=="yes" goto :EOF
echo.
echo CCD [any number or sequence of directory path components] [/R]
echo ... /R causes the drive index to be rebuilt
echo.
echo e.g. -
echo CCD istrator applic data
echo ... C:\Documents and Settings\Administrator\Application Data
echo CCD D: /r
echo ... Causes the index for drive D to be rebuilt
echo.
echo NOTE - Drive specifiers must be the first argument supplied
goto :EOF
:END
:: Clean up (setlocal is not being used due to variable handling issues)
del %INDEX%.tgt 2>nul
del %INDEX%.src 2>nul
set DRIVE=
set DIR=
set REBUILD=
set COUNT=
set INDEX=
set TMPDIR=
set TMPSW=
set ERROR=
set SYNTAXERR=
set REBUILDONLY=
set SW=
set SPECIALCASE=