CD ã³ãã³ãã®æ©è½æ¡å¼µ
ãã®ã¨ããBATã¹ã¯ãªããã®è©±ãé絶ãã¦ãã®ã§ãèªä½ã¹ã¯ãªããã®ç´¹ä»ãcd ã³ãã³ãã® pushd å㨠csh 風æ¡å¼µã移åã¯ãã¹ã¦ pushd ã§è¡ãã
- cd ã®ã¿ã®ã¨ãã¯ãã£ã¬ã¯ããªã¹ã¿ãã¯ã®è¡¨ç¤º
- ãã¼ã (%HOME%)ã¸ã®ç§»å㯠cd ~
- cd - ã§åã®ãã£ã¬ã¯ããªã«æ»ã
- cd åå¨ãããã£ã¬ã¯ã㪠ã ã¨ããã¸ç§»å
- cd åå¨ãããã¡ã¤ã« ã ã¨ãã®ãã¡ã¤ã«ã®ãããã£ã¬ã¯ããªã¸ç§»å
ããã(explorerããcmdããã³ããã¸ãã¡ã¤ã«ããã©ãã°ï¼ããããããã¨ã便å©)
- cd è±æ°å ã§ããã®è±æ°åãç°å¢å¤æ°ã§ããããã®å¤ã "?:\*" ã¤ã¾ããã«ãã¹ã®ãã£ã¬ã¯ããªãªãããã¸ç§»å
- cd æåå ã§ç°å¢å¤æ°CDPATHãæ¢ç´¢ãã¦ãªãã©ã©ã³ããããã«ãã£ã¬ã¯ããªã¨ãã¦åå¨ããã°ããã«ç§»å
- cd /s æåå ã ã¨ãã«ã¬ã³ããã£ã¬ã¯ããªã®ä¸ãå帰çã«æ¢ãã¦æåã«è¦ã¤ãã£ã該å½ãã£ã¬ã¯ããªã«ç§»å
ãã£ã¬ã¯ããªã¹ã¿ãã¯ã®è¡¨ç¤ºã¯ãåã« pushd ã使ãã¨æ°ããé ã«ç¸¦ã«1ã¤ãã¤è¡¨ç¤ºãããããå¤ãé ã«æ¨ªã«ä¸¦ã¹ããã£ããfor /f "delims=" %%A in ('pushd') doã§ã¯ç¾å¨ã®ãã£ã¬ã¯ããªã¹ã¿ãã¯ãåå¾ã§ããªãã'pushd' ã®åºåã¯ç©ºã¨ãªããããããã'pushd' ããµãã·ã§ã«ã§å®è¡ããããã®ãµãã·ã§ã«ã«ç¾å¨ã®ãã£ã¬ã¯ããªã¹ã¿ãã¯æ
å ±ãç¶æ¿ãããªãããã¨æãããããã®ãããä¸æãã¡ã¤ã«ãä½ããããå¾ãªãã£ãã®ãå°ãæ®å¿µã
ãã®ã¹ã¯ãªããã cdd.bat çã¨ãã¦ãdoskey cd=cdd $* ã¨å®ç¾©ãã¦ä½¿ãã
å®é使ã£ã¦ã¿ãã¨ãç°å¢å¤æ°åæå®ã§ã®ç§»åæ©è½ã¾ã§ã¯è¦ããªãã£ãããªã¨æãããããçãã°20è¡ã»ã©çãåºæ¥ãã
@echo off if "%~1"=="" ( %å¼æ°ãç¡ããã°è¡¨ç¤ºã®ã¿% ãcall :dirs ãgoto :eof ) if "%~1"=="-" ( % - ãªãæ»ã£ã¦è¡¨ç¤º% ãpopd ãcall :dirs ãgoto :eof ) if "%~1"=="~" if defined HOME ( % ~ ãªããã¼ã ã¸% ãcall :pushd %HOME% ãgoto :eof ) if exist "%~1" ( %åå¨ãããï¼% ãif exist "%~1\" ( %ãã£ã¬ã¯ããªãï¼% ããcall :pushd "%~1" ã) else ( %æ®éã®ãã¡ã¤ã«ã % ããcall :pushd "%~dp1" ã) ãgoto :eof ) setlocal enabledelayedexpansion call :isname "%~1" if %ERRORLEVEL%==0 ( %è±æ°åã ãã®ååãï¼% ãif defined %1 ( %ç°å¢å¤æ°åãï¼% ããset "Q=!%1!" ããif "!Q:~1,2!"==":\" if exist !%1!\ ( %å 容ããã£ã¬ã¯ããªçµ¶å¯¾ãã¹ãï¼% ããã endlocal&call :pushd %%%1%% ããã goto :eof ãã) ã) ) set "P=%~$CDPATH:1" %CDPATHã®æ¢ç´¢% if defined P if exist "!P!\" ( %è¦ã¤ãã£ãï¼% ãendlocal&call :pushd %~$CDPATH:1 ãgoto :eof ) endlocal if /i "%1"=="/s" if not "%2"=="" for /r %%A in (%2) do if exist %%A\ ( ã%第ä¸å¼æ°ã /s ãªããµããã£ã¬ã¯ããªãæ¢ã% ãcall :pushd %%A ãgoto :eof ) call :pushd %* goto :eof :isname %è±æ°åã¨ä¸é¨ã®è¨å·ã ãããã§ãã¯% setlocal enabledelayedexpansion set "W=%~1" 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 _ ã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 0 1 2 3 4 5 6 7 8 9) do ( ãif not defined W endlocal&exit /b 0 ãset "W=!W:%%A=!" ) endlocal exit /b 1 :pushd %pushdãæåãã¦ãå ã¨åããªãpopdãã(å±¥æ´ãæ®ããªããã)% for /f "delims=" %%X in ("%CD%") do ( ãpushd %* ãif not ERRORLEVEL 1 for /f "delims=" %%Y in ('echo %%CD%%') do ( ããif "%%X"=="%%Y" popd ã) ) goto :eof :dirs %ãã£ã¬ã¯ããªã¹ã¿ãã¯ãå¤ãé ã«æ¨ªã«ä¸¦ã¹ã¦è¡¨ç¤ºãã% setlocal enabledelayedexpansion set TEMPFILE="%TEMP:"=%\cd$$%TIME::=.%.tmp" pushd > %TEMPFILE% set DIRS= for /f "usebackq delims=" %%A in (%TEMPFILE%) do set "DIRS=%%A !DIRS!" del %TEMPFILE% 2>NUL if defined DIRS echo %DIRS% endlocal goto :eof
ãã£ã¬ã¯ããªã¹ã¿ãã¯ã«åããã®ãé£ç¶ããªãããã«å·¥å¤«ããã®ããã« :pushd ã¨ãããµãã«ã¼ãã³ãä½ã£ãããsetlocal ã使ããªã( setlocal 㨠endlocal ã®é㧠pushd ããã¨ãendlocal ã§å ã«æ»ã£ã¦ãã¾ããunix ã® ã·ã§ã«ã¹ã¯ãªããå 㧠cd åºæ¥ãªãã®ã¨åã) ã®ã§ç°å¢å¤æ°ãæ±ããªãããã« for/f ã®å¶å¾¡å¤æ°ã«æ°æ§ã®ãã£ã¬ã¯ããªãã»ãããã¦æ¯è¼ããããå¾ãªãã£ããå¾ã§èããã¨ãOLDCD ã®ãããªç°å¢å¤æ°ãæ°è¨ãã¦ä½¿ãæããã£ãã