문제

I'm using Powershell and imagemagick to create a simple code to append images. 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.

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

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".

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.

P.S. 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. So I need the command to build on the "PS C:\...\image-converter>" path that Powershell will be run from.

도움이 되었습니까?

해결책

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.

다른 팁

Use environment variables to get the userprofile, and then your subdirectorys:

$env:userprofile

Will give you your 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top