Windows komut satırında hızlı ve etkin bir şekilde dir nasıl değiştirilir?


1

Mesela ben varım C:\test1ve başka bir dizine sahibim C:\test2\sub2

Bir komut satırı aracının geçiş yapmasını istiyorum sub2 hızlıca şöyle:

quickchange sub2

... ve bu program tüm diskin dizin veritabanını ayarlayabilir ve veritabanını elle güncelleyebilir.

Peki, Windows komut satırında gereksinimlerime uygun bir araç var mı?

(ps: cygwin kullanmak istemiyorum)

Düzenle : Programın nerede olduğunu bulmak için veritabanında arama yapabilmesini istiyorum sub2 ikamet eder ve ona değişir. Birden fazla dizin eşleşirse, benden seçmemi ister.

Adında küçük bir araç biliyorum QCD işi yapabilir, ancak QCD uzun zamandır güncellenmedi ve bazı hatalar var.

Yanıtlar:


2

Bunu gerçekten yapamazsın. Teknik açıdan biraz imkansız.

Bunun gibi bir klasör yapısına sahip olduğunuzu hayal edin:

School Work/
    English/
        Assignments/
        Class Work/
        Documents/

    Science/
        Assignments/
        Class Work/
        Documents/

    Math/
        Assignments/
        Class Work/
        Documents/

Şimdi koştuysan quickchange Documents School Work klasörü içinden, hangi klasöre gitmeyi beklersiniz? Üç eşleşme var ve hangisine ulaşmak istediğinizi bilmenin bir yolu yok. Elbette, hangi klasörün peşinde olduğunuzu sorabilir, ancak bu çok iyi ölçeklenemez.

Bu aynı klasör yapısını okuldaki, sunucudaki her öğrenci için düşünün;

Josh Hunt\
    School Work\
        [etc]

Cathy Wells\
    School Work\
        [etc]

Jack Thompson\
    School Work\
        [etc]

James Smith\
    School Work\
        [etc]

[repeat for all 1300 students]

Açıkçası, bu iyi ölçeklenmiyor. Şimdi 3900 Belge klasörü var.

Klasörleri gezinmeyi kolaylaştırmanın tek yolu Sekme Tamamlama'yı kullanmaktır. Bunu böyle kullanırsın:

/Schoolwork/$ dir E<tab>[nglish/]A<tab>[ssignments/]

Sadece netleştirmek için, <tab> klavye üzerindeki sekme tuşuna bastığınızı belirtirken [nglish/] hangi sekme tamamlama işleminin sizin için doldurulduğunu gösterir.


1
+1, sekme tamamlamadan ne yapacağımı bilmiyorum :)
quack quixote

bu nedenle, aracın bana aynı adlandırılmış dir için bir seçim verebileceğini umuyorum, küçük bir araç QCD bu işi yapabilir, ancak QCD uzun zamandır güncellenmedi ve birkaç hataya sahip.
Zhongshu

2

Ben yazdım cd On yıldan daha uzun bir süre önce Perl'de değiştirme, bu bir DOS komut satırında ksh benzeri özellikler (örneğin CDPATH, cd -, $ OLDPWD) verir. Sekme tamamlama dışında bir şey yapamazsınız, çünkü bu bir kabuk değişimi olmadığı için yapamaz. cd değiştirme, böylece vurduğunuzda <TAB> Hala emir altındasın. Kodu biraz temizlemek zorunda kalacağım (bu yüzden utanmıyorum; hata açısından oldukça sağlam), ancak ilgilenirseniz gönderebilirim.

İşte bunun için yerleşik yardım:

=============================================================================
cdp - provides UNIX-style cd capabilities under Win32
Copyright (C) 1997-8, Joseph L. Casadonte Jr. All rights reserved.
Version: 2.12

Usage: cdp [-h | -help]
       cdp -
       cdp [-x] [-unix | -dos]
       cdp [-x] -quote <AbsolutePathName>
       cdp [-x] -quote [-look <dir> | -exc <dir>] <Target>
       cdp [-x] <oldpart> <newpart>
       cdp [-x] [-noquote] <AbsolutePathName>
       cdp [-x] [-noquote] [-look <dir> | -exc <dir>] <Target>

Commands are interpretted in the order given above.  Note: the presence of
the -[no]quote option affects the order.

options:
    -h      Get help (this message) and exit
    -help   Get help (this message) and exit

    -x      suppresses the evaluation of $CDP.

    -dos    cdp with no arguments echos current working directory
    -unix   cdp with no arguments changes to root of current directory
            [default: -unix]

    -quote  will assume multiple words in <Target> or <AbsolutePathName>
            are quoted together (i.e. program files will be interpreted
            as 'program files').  May be negated (-noquote).  Used mainly with
            $CDP (see below).  [default: -noquote]

    -look <dir>  will attempt to find a matching directory by appending <dir>
                 to each element of $CDPATH\<Target>, or failing that, by
                 matching an element of $CDPATH\<Target> itself.  May be
                 specified more than once:

                    cdp -look foo -look bar perl5

                 Cannot be used in conjunction with -exc.  Used mainly with
                 $CDP (see below).

    -exc <dir>   will look exclusively for a matching directory by appending
                 <dir> to each element of $CDPATH\<Target>.  If no exact
                 match is found it will *not* match to an element of
                 $CDPATH\<Target> alone.  Cannot be used in conjunction with
                 -look.  Used mainly with $CDP (see below).

cdp -
-----
Will change to the immediately previous directory ala UNIX by using the
$OLDPWD environment variable.

cdp [-unix | -dos]
------------------
Will either change to the root directory (-unix option) or echo the current
directory (-dos option).

cdp [-quote] <AbsolutePathName>
-------------------------------
Will attempt to change into the directory <AbsolutePathName>.  Note:
<AbsolutePathName> is anything that begins with a drive letter (e:\foo), a
front- or back-slash (\temp) or a period (../foo).

cdp [-quote -look <dir> -exc <dir>] <Target>
--------------------------------------------
cdp will use the environment variable $CDPATH to find a valid directory to
change into by appending <Target> to each element in $CDPATH until a match is
found.  $CDPATH (or %CDPATH% for the dos-heads) is a semi-colon delimited
list of directories.  Directories with spaces in them are fine
(i.e. c:\program files) but UNC names are not (i.e. \\machine\share).  The
order of the directories in $CDPATH is important, as the first match wins.
Once a valid directory is found, cdp will change to that directory,
changing drives if necessary.  cdp will not match the current working
directory.

You may include the current directory in the CDPATH environment variable by
using the '.' (i.e. set CDPATH=.;c:\my documents;d:\source).  Most people
will put this at the very beginning of their CDPATH.  It is also extremely
useful if using aliasing (see below).

The two options, -look and -exc, provide ways of extending the match criteria.
If you always change into the source directory of a project (xxx\src), then
you can put the option "-look src" in your $CDP variable, to always look for
a "src" directory when a match on <Target> is found.  Multiple "-look <dir>"
options are resolved in the order given on the command line.  If none are
found, the match to <Target> alone stands.  The "-exc <dir>" option is used to
look exclusively for a particular match to <Target>\<dir>.  If one is not
found, no match is returned (i.e. <Target> alone will not match).  See the
Examples below for more info.

cdp <oldpart> <newpart>
-----------------------
You can substitute a piece of the current directory name specified by <oldpart>
with <newpart>.  For example, if you were in the directory:

   c:\release\really\long\directory\structure\src

you could type:

   cd release debug

and find yourself in:

   c:\debug\really\long\directory\structure\src

assuming it exists.  See examples below.

=============================================================================
Examples
========

Given the following directory structure:

    e:\program files
    e:\program files\perl5
    e:\program files\perl5\docs
    e:\program files\perl4

    e:\program
    e:\program\perl5
    e:\program\perl5\docs

    e:\files
    e:\files\perl5
    e:\files\perl5\docs

and the following Environment Variables:

    set CDPATH=.;e:;e:\program files
    set CDP=-quote
    set OLDPWD=e:\files\perl5

this command                 in this directory       will result in this
-----------------            ---------------------   -------------------------
cdp perl5                    c:\                     e:\program files\perl5
cdp perl5                    e:\program files        e:\program files\perl5
cdp perl5                    e:\program              e:\program\perl5

cdp e:\files\perl5           <anywhere>              e:\files\perl5
cdp \program                 e:\<anywhere>           e:\program
cdp ..\perl5                 e:\program files\perl4  e:\program files\perl5

cdp -unix                    e:\program files\perl5  e:\
cdp -dos                     e:\program files\perl5  e:\program files\perl5

cdp -                        <anywhere>              e:\files\perl5

cdp program files            e:\program\perl5        e:\program files
cdp -x program files         e:\program\perl5        e:\files\perl5
cdp 'program files'          e:\program\perl5        e:\program files
cdp -noquote 'program files' e:\program\perl5        e:\program files
cdp -noquote program files   e:\program\perl5        e:\files\perl5
cdp -x -quote program files  e:\program\perl5        e:\program files

cdp -look docs perl5         c:\                     e:\program files\perl5\docs
cdp -look docs perl4         c:\                     e:\program files\perl4

cdp -exc docs perl5          c:\                     e:\program files\perl5\docs
cdp -exc docs perl4          c:\                     cdp: path not found

=============================================================================
Backslash ('\') vs. Frontslash ('/')
====================================
cdp allows you to use, and even mix, backslashes and frontslashes together.
The following are identical:

   cdp c:\program files\perl5
   cdp c:/program files/perl5
   cdp c:\program files/perl5
   cdp c:/program files\perl5

=============================================================================
Aliasing
========

It is possible to alias the DOS command 'cd' to be cdp.  This way, you
use the features of cdp without having to remember to type a seperate
command.  To do this, you need to use a DOSKEY macro.  For example:

    doskey cd=cdp $*

The "$*" tells DOSKEY to pass all the arguments it received to the new program.

To remove the alias, type:

    doskey cd=

If you ever need to invoke the regular DOS 'cd' command, you can always use
'chdir'.

For more information, type:

    doskey /?

=============================================================================
Environment Variables
=====================
Note: Environment Variables are case sensitive for Perl.

CDPATH - semi-colon delimited list of directories to search thru
         [default: "."]
         [$CDPATH: ".;c:\my documents;l:\gc3\glog_deploy\web\xsl;l:\gc3\glog_deploy\web;l:\gc3\glog\server;l:\gc3\glog\oracle;c:\sandbox;c:\my documents\home_page;\;"]

CDP - a set of default options to be used each time cdp is invoked. This
      is so you do not have to specify the same options every time you use
      cdp.

      These options are processed *before* any options on the command line, and
      can be overridden (i.e. if -quote is set in $CDP, -noquote on the command
      line overrides it).  The use of $CDP can be suppressed by specifying
      the -x option on the command line.
      [$CDP: "-quote"]

CDPFNAME - filename to be used by the Perl script to communicate with the
           surrounding batch script (this is a serious hack!).  Can be changed
           at the top of the script.
           [$CDPFNAME: "c:\temp\cdpath.bat"]

TEMP - used by the scripts to create $CDPFNAME.
       [$TEMP: "c:\temp"]

OLDPWD - used to store the previous directory (see "cdp -" invocation)

=============================================================================
Files used
==========
%TEMP%\cdpath.bat - file used by the Perl script to communicate with the
                    surrounding batch script.  Can be changed to whatever
                    is needed at the top of the script.

=============================================================================
Contacting the Author/Latest Version
====================================
Please send questions, bug reports and comments to: joc@netaxs.com
You can get the latest version at: http://www.netaxs.com/~joc/perl.html

=============================================================================
=============================================================================

güzel gözüküyor. OP’nin özelliklerini yerine getireceğinden emin değilim, ama bir kopyasını almakla ilgileniyorum
quack quixote

1

'Subst' öğesini de kullanabilirsiniz

Bir dizine bir sürücü harfi atayalım. Böylece X olarak 'benim eşyalarım \ ne olursa olsun \ dunno \ bir şey' dizinini ayarlayabilirsiniz: ve Y'ye '\ daha fazla şey \ o şeyi değil \ ama \ bu şeyi \ ayarlayabilirsiniz:

Artık normalde yapacağınız her şeyi yapmak için sürücü harfini kullanabilirsiniz.


1

Kullanabilirsiniz ColorConsole diğer pek çok güzelliğin yanında çoklu CMD ile sekmeli arayüz ve favori komutlar , hayatı LOT kolaylaştırır.

alt text

ColorConsole ücretsiz ve taşınabilirdir (kurulum gerektirmez).


1

Geç cevap için özür dilerim, bu soruyu bulmam birkaç yıl sürdü.

Bunu yapan bir toplu iş komut dosyası kullanabilir, ardından bir toplu iş komut dosyasını DOSKEY makrosu ile kullanabilir veya yolunuza koyabilirsiniz.

Bu betiği yazdım, aşağıdaki kullanım durumları var:

  1. Dizin, alt dizinlere bakmadan mevcutsa, ona geçin.
  2. Bir eşleşme bulunursa, buna geçin.
  3. Birden fazla eşleşme bulunursa, bunları listeleyin ve bir seçim isteyin.
  4. Eşleşme bulunamazsa, "Dizin bulunamadı" ifadesini görüntüleyin.
  5. Herhangi bir argüman verilmezse, tüm alt dizinleri listeleyin ve bir seçim isteyin.

İşte betiğim:

@echo off

setlocal enabledelayedexpansion

set target_directory=%1
set /a prompt_index=0
if exist %target_directory% (
    set chosen_path=%target_directory%
    goto :path_set
)
for /f "tokens=*" %%A IN ('dir /s /b /ad %1 2^>nul') do (
    SET /a prompt_index+=1
    set dir_!prompt_index!=%%A
)
if %prompt_index%==0 (
    echo Directory not found
) else if %prompt_index%==1 (
    set chosen_index=1
) else if %prompt_index% GTR 1 (
    for /l %%i in (1, 1, %prompt_index%) do (
        echo %%i. !dir_%%i!
    )
    echo.
    set /p chosen_index="Choose a directory: "
)
set chosen_path=!dir_%chosen_index%!
:path_set
endlocal & set chosen_path=%chosen_path%
if defined chosen_path (
    pushd %chosen_path%
    set chosen_path=
)

0

CD'den sonra sekmenin otomatik tamamlaması yeterince hızlı değil mi? Genellikle bu şekilde gitmem gereken yere ulaşmak için sadece 5 veya 6 tuşa basmam gerekiyor.


Çünkü sub2 asistanının nerede olduğunu hatırlamıyorum, tüm disk için her dizinin zor olduğunu hatırlıyorum;)
Zhongshu

1
Bu, sistemde hiçbir yerde aynı ada sahip iki dizininiz olmadığını varsayar. Bununla iyi şanslar
MDMarra

@ Zhongshu Çoğu insan var bazı bilgisayarlarında dosya ve klasörlerin nasıl düzenlendiği hakkında bir fikir.
Josh Hunt

bu nedenle, aracın bana aynı adlandırılmış dir için bir seçim verebileceğini umuyorum, küçük bir araç QCD bu işi yapabilir, ancak QCD uzun zamandır güncellenmedi ve birkaç hataya sahip.
Zhongshu


0

kullanım pushd ve popd.

C:\Documents and Settings\~quack> pushd d:\foo

D:\foo> pushd e:\bar

E:\bar> popd

D:\foo> popd

C:\Documents and Settings\~quack>

pushd geçerli dizinizi bir yığına iter, sonra cd bağımsız değişken dizinine. Yığın istediğiniz kadar büyük olabilir. popd yığının en üstündeki dizini siler ve cd 's.


0

örneğin, c: \ test1'deyim ve başka bir c: \ test2 \ sub2 dizinim var

Farz ediyorum

c:\test1>cd c:\test2\sub2

seçenek değil mi
Dizinler arasında geçiş yapmak için her zaman geçmişi kullanabilirsiniz (F7 tuşuna basın).

Bir komut satırı aracının aşağıdaki gibi hızlı bir şekilde sub2'ye geçmesini istiyorum:
quickchange sub2
ve bu program tüm diskin dizin veritabanını ayarlayabilir ve veritabanını manuel olarak güncelleyebilir.

Ve varsa (ve her zaman olacağını varsayalım) "sub2" adında iki dizin? Bu kavram tam olarak böyle olmayacak.

Yani, Windows komut satırında benim ihtiyacım için uygun bir araç var mı?

Benzer bir şey var pushd ve popd cmd yardımınıza. İki dizin arasında hızlıca geçiş yapmanızı sağlar.

Buraya bakınız:

C:\test1>pushd c:\test2\sub2  
c:\test2\sub2>pushd C:\test1  
C:\test1>popd  
c:\test2\sub2>popd  
... to infinity  

ancak birden fazla dizin arasında geçiş yaparken yine de sorun yaşayacaksınız.

(ps: cygwin kullanmak istemiyorum)


0

Böyle bir şey dene:

@ECHO OFF
goto %1
:docs
cd c:\Users\Phoshi\Documents
GOTO END
:userdir
cd c:\users\Phoshi
GOTO END
:programfiles
cd "c:\program files"
GOTO END
:startup
cd c:\Users\Phoshi\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
GOTO END
:logs
cd "c:\Program Files\Miranda-IM\Logs\"
GOTO END
:music
cd C:\Users\Phoshi\Audio
GOTO END
:pictures
cd C:\Users\Phoshi\Pictures\
GOTO END
:drop
cd "C:\Users\Phoshi\Documents\Drop Box\"
GOTO END
:system32
cd "C:\Windows\System32\"
goto end
:fallout
cd "c:\Program Files\Bethesda Softworks\Fallout 3\"
goto end
:end

Bir toplu iş dosyası olarak kaydedin, yolunuza koyun (örneğin, \ system32) ve ardından, belgelerinize gitmek için "go docs" deyin İsterseniz, onları yönetmenize yardımcı olacak küçük bir program yazabilirsiniz.

Sahip olduğunuz özel örnek çok zor olurdu ve iki dizin aynı ada sahip olsaydı muhtemelen işe yaramazdı.

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.