简体   繁体   English

在Powershell命令中使用单独的文件夹

[英]Using separate folders in powershell command

I'm using Powershell and imagemagick to create a simple code to append images. 我正在使用Powershell和imagemagick创建一个简单的代码来追加图像。 I need to Powershell to be run from one folder, the input images to be take from a sub-folder, and the output images to be taken from a subfolder of that folder. 我需要从一个文件夹运行Powershell,从一个子文件夹获取输入图像,并从该文件夹的一个子文件夹获取输出图像。

For example, the folder structure goes: 例如,文件夹结构为:

\image-converter\Append-images\Appended

So Powershell will be run from the "image-converter" folder, and will open with the directory: PS 因此,Powershell将在“ image-converter”文件夹中运行,并使用以下目录打开:PS

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

The input images to be appended will be stored in the folder "Append-images", and the output images will be saved to the folder "Appended". 要添加的输入图像将存储在文件夹“ Append-images”中,输出的图像将保存到文件夹“ Appended”中。

An example of the command I will be using is: 我将使用的命令示例是:

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

So I would need to modify the command to take the input images from \\Append-images and save the output images to \\Append-images\\Appended. 因此,我需要修改命令以从\\ Append-images中获取输入图像,并将输出图像保存到\\ Append-images \\ Appended中。

PS I can't use the full "C:\\..." path as this will be used by different people and the image-convert folder will be saved in different places. PS我不能使用完整的"C:\\..."路径,因为这将由不同的人使用,并且图像转换文件夹将保存在不同的位置。 So I need the command to build on the "PS C:\\...\\image-converter>" path that Powershell will be run from. 因此,我需要在Powershell将从其运行的"PS C:\\...\\image-converter>"路径上构建命令。

Use environment variables to get the userprofile, and then your subdirectorys: 使用环境变量获取用户配置文件,然后获取子目录:

$env:userprofile

Will give you your C:\\Users\\User1 会给你你的C:\\Users\\User1

If you want to make the folders, do the following: 如果要制作文件夹,请执行以下操作:

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

And then work with those. 然后与那些人一起工作。

How about this. 这个怎么样。

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

That should give you the location you need to browse the subsequent files. 这应该为您提供浏览后续文件所需的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM