カレントディレクトリの取得
シェルスクリプト
$ pwd
PowerShell
Get-Location
オブジェクトとして得られる。(Path)
https://docs.microsoft.com/ja-jp/powershell/scripting/samples/managing-current-location?view=powershell-7.1#getting-your-current-location-get-location
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-location?view=powershell-7.1
code:get_current_dir.ps1
$curDir = $(Get-Location).Path
Convert-Path .
相対パスから絶対パスへの変換コマンドレットに.でカレントディレクトリの相対パスを渡す。
文字列として得られる。
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/convert-path?view=powershell-7.1
code:get_current_dir.ps1
$curDir = $(Convert-Path .)
Windows コマンドプロンプト
%CD% 環境変数
変数として取り扱うには CD 環境変数を使うのが簡単
chdir コマンド(引数指定なし)
$ chdir
JavaScript(Node.js)
process.cwd()
https://nodejs.org/api/process.html#process_process_cwd
フルパスが返ってくる。