Using separate folders in powershell command - image

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.

Related

use the zip command specifying different path from current directory

We have a set of unix tools that were ported to windows and I want to use the zip command to package a set of files.
I'm trying to do this:
Open cmd from desktop and take the files in r:\pam\client\ssb\portfoliorepportcards\202003\*.docx and create a zip file in r:\pam\client\ssb\PortfolioReportCards\202003.zip with the files in it.
My command is:
C:\Users\JPalomino\Desktop>zip.exe -b "r:\pam\client\ssb\PortfolioReportCards" 202003.zip . -i r:\pam\client\ssb\portfoliorepportcards\202003\*.docx
zip error: Nothing to do! (202003.zip)
and I get nothing
However when I cd to r:\pam\client\ssb\portfoliorepportcards and do
R:\Pam\Client\SSB\PortfolioReportCards>zip -r 202003.zip . -i \202003\*.docx
it works like a charm. Also I wouldn't want the folder structure in it.
Could you please tell me what I'm doing wrong in the command? It seems such an easy thing to ask from zip.
Thanks
Maybe this will help, you don't need zip.exe (if you have powershell 5 or higher)...
powershell -command "Compress-Archive -Path 'r:\pam\client\ssb\PortfolioReportCards\*' 'r:\pam\client\ssb\PortfolioReportCards\202003.zip'"
I saw you're having trouble zipping to another drive letter, this should help with that too. I'm not really familiar with zip.exe to know why that's giving your grief.
Anything else you "port" to cmd is probably better off as a powershell. --- also if "zip.exe" isn't on your desktop that could possibly be your problem right there. If it works when you CD that tells me it's probably located where you're CD'ing to. Perhaps add zip.exe as an environment variable so that it can be accessed globally instead of only from the working directory.
And my take one your command (If zip is actually on your desktop or set as environment variable... : zip.exe -b "r:\pam\client\ssb\PortfolioReportCards" 202003.zip . -i r:\pam\client\ssb\portfoliorepportcards\202003\*.docx
I would re-write that and try this instead (because traditionally the filepath is all in quotes for any other windows command I know of)...
zip.exe -b "r:\pam\client\ssb\PortfolioReportCards\202003.zip" . -i r:\pam\client\ssb\portfoliorepportcards\202003\*.docx

Is there a power shell command to add a zipped folder to a location on a network location?

I am very new to Powershell but have learned that is a very powerful tool to master. I am attempting to take a folder from a location on my PC, Zip it and then paste it into a folder located on a network drive. I have figured out how to create a zip of a folder and send it to a location on my machine but can not figure out how to send it to anywhere else.
Is this the way to go about it?
Is this even possible?
I have been able to use
"Compress-Archive -Path C:\ProgramData\Microsoft C:\users\MYACT\Desktop\Folder"
(I am using goolge as an example because i am not sure if i can put the actual location on here )
I am attempting to use (but failing)
"Compress-Archive -Path C:\ProgramData\Microsoft ftp://ftp.google.com\parent\Sub"
When Run the command i receive
Compress-Archive : The path 'ftp:\ftp.google.com\parentFolder\SubFolder' either does not exist or is not a valid
system path.

How to use short-cut paths to Compress-Archive to zip current folder into same destination

I am using Compress-Archive and want to zip the current directory into the same path. However I do not want to have to type out the entire file path both times. Is there an easy way to do this?
I am using windows 10 pro.
This works for the most part Compress-Archive . test.zip but I want it to be on the same level as the current directory so I need to put it back one spot.
Something like this is what I want:
path/test
path/test.zip
What I am getting:
path/test
path/test/test.zip
It is going inside the actual folder which is not what I want
You propably want that:
Compress-Archive * ..\test.zip
The wildcard * avoids that the name of the folder is put inside the zip.
Using .. for the output path we go one level up in the directory tree.
This command will fail if test.zip already exists. Either add parameter -update to update the archive or add -force to overwrite the archive. Both can be used even if the archive does not already exist.
If the current working directory is "t", it can be included using the following command. I would note that I do not think putting the destination .zip file in the directory being compressed is a good idea.
Compress-Archive -Path $(Get-ChildItem -Recurse -Exclude t.zip) -DestinationPath .\t.zip -Force
It is shorter if you are willing to use aliases and cryptic switches.
Compress-Archive $(gci -r -e t.zip) .\t.zip -Force
If I have misinterpreted your situation, please leave a comment or improve the information provided by editing the question.

How can I organize recovered files into separate folders by file type?

I've got 218GB of assorted files recovered from a failing hard drive using PhotoRec. The files do not have their original file names and they're not sorted in any manner.
How can I go about sorting the files into separate folders by file type? I've tried searching for .jpg, for example, and I can copy those results into a new folder. But when I search for something like .txt, I get 16GB of text files as the result and there's no way I've found to select them all and copy them into their own folder. The system just hangs.
This is all being done on Windows 10.
Open powershell. Change to the recovered data folder cd c:\...\recovered_files. Make a directory for the text files mkdir text_files. Do the move mv *.txt text_files.
You really just want to move/cut the files like this instead of copying, because moving the files is just a name change (very fast), but to copy would have to duplicate all of the data (quite slow).
If your files are distributed among many directories, you would need to use a find command. In Linux, this would be quite simple with the command, find. In Windows, I have never tried anything like this. On MSDN there is an article about PowerShell that features an example which seems reminiscient of what you want to do. MSDN Documentation
The gist of it is that you would use the command:
cd <your recovered files directory containing the recup_dir folders>
Get-ChildItem -Path ".\*.txt" -Recurse | Move-Item -Verbose -Destination "Z:\stock_recovered\TXT"
Note that the destination is outside of the search path, which might be important!
Since I have never tried this before, there is NO WARRANTY. Supposing it works, I would be curious to know.

Windows 10 - how to compress file without creating a parent folder

In Windows 10,
from power shell, I want to compress a folder without it creating a parent folder inside the zip file
currently I use:
Compress-Archive -Path . ../abc.zip
Is it possible to create the archive without the parent folder?
You might try this (didn't test it and I don't even have any window installed, so might not work):
gci c:\folder\* | Compress-Archive -DestinationPath c:\abc.zip

Resources