簡體   English   中英

在Powershell命令中使用單獨的文件夾

[英]Using separate folders in powershell command

我正在使用Powershell和imagemagick創建一個簡單的代碼來追加圖像。 我需要從一個文件夾運行Powershell,從一個子文件夾獲取輸入圖像,並從該文件夾的一個子文件夾獲取輸出圖像。

例如,文件夾結構為:

\image-converter\Append-images\Appended

因此,Powershell將在“ image-converter”文件夾中運行,並使用以下目錄打開:PS

C:\Users\name\Downloads\image-converter>

要添加的輸入圖像將存儲在文件夾“ Append-images”中,輸出的圖像將保存到文件夾“ Appended”中。

我將使用的命令示例是:

  • convert +append input.png input.png output.png

因此,我需要修改命令以從\\ Append-images中獲取輸入圖像,並將輸出圖像保存到\\ Append-images \\ Appended中。

PS我不能使用完整的"C:\\..."路徑,因為這將由不同的人使用,並且圖像轉換文件夾將保存在不同的位置。 因此,我需要在Powershell將從其運行的"PS C:\\...\\image-converter>"路徑上構建命令。

使用環境變量獲取用戶配置文件,然后獲取子目錄:

$env:userprofile

會給你你的C:\\Users\\User1

如果要制作文件夾,請執行以下操作:

mkdir $env:userprofile\images
mkdir $env:userprofile\images\AppendImages
mkdir $env:userprofile\images\Output

然后與那些人一起工作。

這個怎么樣。

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Get-Content -path "$scriptPath\Append-images\"

這應該為您提供瀏覽后續文件所需的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM