Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

January 29, 2002 12:00 AM

JSI Tip 4757. CMD prompt folder navigation tool?

Windows IT Pro
InstantDoc ID #76063
Rating: (0)


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 supplied
On 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=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=


Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.