質問

現在の作業ディレクトリへのフルパスを取得するために使用できるWindowsコマンドラインコマンドはありますか?

また、バッチファイルで使用される変数内にこのパスを保存するにはどうすればよいですか

役に立ちましたか?

解決

シェルを直接使用している場合は引数なしで cd を使用します。バッチファイルで使用する場合は%cd%を使用します(環境変数)。

他のヒント

次のようにバッチ/環境変数を設定できます:

SET var=%cd%
ECHO %var%

Windows 7 x64 cmd.exeのスクリーンショットのサンプル。

ここに画像の説明を入力

SET var =%cd%の代わりに SET var =%cd%を実行した場合、

更新: >、以下が何が起こるかです。 jebに感謝します。

ここに画像の説明を入力

現在のディレクトリをバッチファイルからキャプチャする

set コマンドのWindowsヘルプを引用( set /?):

If Command Extensions are enabled, then there are several dynamic
environment variables that can be expanded but which don't show up in
the list of variables displayed by SET.  These variable values are
computed dynamically each time the value of the variable is expanded.
If the user explicitly defines a variable with one of these names, then
that definition will override the dynamic one described below:

%CD% - expands to the current directory string.

%DATE% - expands to current date using same format as DATE command.

%TIME% - expands to current time using same format as TIME command.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current Command Processor Extensions
    version number.

%CMDCMDLINE% - expands to the original command line that invoked the
    Command Processor.

%CD%-現在のディレクトリ文字列に展開されることに注意してください。 部分。

Unixの場合

pwd

これは常に私のために働いています:

SET CurrentDir="%~dp0"

ECHO The current file path this bat file is executing in is the following:

ECHO %CurrentDir%

Pause

Windowsの場合

cd

およびLinuxの場合

pwd

コマンドがあります。

Windowsの場合、 cd だけで現在の作業ディレクトリが表示されます。

UNIXおよび類似システムの場合、 pwd は同じタスクを実行します。一部のシェルで $ PWD シェル変数を使用することもできます。 Windowsがシェル変数を介した現在の作業ディレクトリの取得をサポートしているかどうかはわかりません。

Windowsの場合:

CHDIR 現在のディレクトリの名前を表示または変更します。

Linuxの場合:

PWD 現在のディレクトリの名前を表示します。

chdir投稿へのコメントのフォローアップの質問(変数にデータを保存)に基づいて、ディレクトリを変更した後、現在のパスを復元するために現在のパスを保存したいのです。

元のユーザーは、「pushd」を確認する必要があります。これにより、ディレクトリが変更され、「popd」で復元できるスタックに現在のディレクトリがプッシュされます。バッチファイルを作成するときの方法である、最新のWindows cmdシェル。

実際に現在のパスを取得する必要がある場合、最新のcmdシェルには、参照用に別の変数に簡単に格納できる%CD%変数もあります。

@for /f "usebackq" %%x in (`chdir`) do set var=%%x
@echo "The currenct directory is: %var%"

しかし、もちろん、gmaran23の答えははるかに簡単です。

System32 .bat ファイルを作成し、 copypath.bat という名前を付けて、現在のパスをコピーするコマンドを

echo %cd% | clip

説明:

%cd%は現在のパスを提供します

CLIP

Description:
    Redirects output of command line tools to the Windows clipboard.
    This text output can then be pasted into other programs.

Parameter List:
    /?                  Displays this help message.

Examples:
    DIR | CLIP          Places a copy of the current directory
                        listing into the Windows clipboard.

    CLIP < README.TXT   Places a copy of the text from readme.txt
                        on to the Windows clipboard.

現在、 copyclip はどこからでも利用できます。

Windowsコマンドプロンプトで、 chdir または cd は、コンソールの現在の作業ディレクトリの完全なパスを出力します。

パスをコピーする場合は、次を使用できます。クリップ。

Windowsでは、現在の作業パスに cd と入力します。

Linuxでは、現在の作業パスの pwd

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top