Copying Images(.JPG) to a Zip Folder prior to Sftp

$Images = Get-ChildItem -Path C:\Photos*.jpg

i test the variable using $Source and see that the images are there.

Foreach ($. in $Source){
Copy-ImageToOrganizedFolder -Path C:\Photos2$
.Jpg
Start-Sleep -Milliseconds 2000
}

I am then prompted for a Value,
WHich then gives an error the path’s format is not supported.
This is just in test phase. i have tried many variations including copy-toZip

What i will eventually be doing is copying thousands of .jpeg’s to a Zipped folder verbatim.
There can be no name changes or resizes(resizing is my next project which will be implemented before this one)
JUst a copy to zip as is. I have an ssis package which will then sftp the folder/contents
i will also then need to implement the archive attribute so in future runs only uncopied images will be processed
(this may change due to people changing their images.)
But for now can someone help me with the basic get images >> copy and write to Zip location.

I thank you for the code and help and ask if it isnt to much to add lots of comments as i need to know what is happening and why or i feel i will never learn.

$_ is an automatic variable that sometimes gets assigned by the PowerShell engine. It’s kind of confusing to use it as your own variable name in something like a ForEach loop, and may cause you problem later on.

To provide much more help than that, we’d need to see what’s being assigned to you $Source variable, as well as the code in Copy-ImageToOrganizedFolder (which I’m assuming is a function elsewhere in your code.)

The $source is supposed to contain 6 images that were copied using the get-childitem. i am using the examples photos provided in windows 7.
The Copy-imagetoarganisedfolder is part of the PS pack. i have not created my own function.
I am one of the nOObs referred to in the forum guide. :slight_smile:
so creating my own functions is a step or two away for me yet i think.

I’m not familiar with the Copy-ImageToOrganizedFolder command or where you’re getting it from, so I can’t help you much there. It looks like maybe you’re trying to use two different variable names for the same thing ($Source and $Images), since in your post, $Images seems to match the description of what you say is in $Source.

Based on what I can see, here’s how I’d modify your code:

Get-ChildItem -Path C:\Photos\*.jpg |
ForEach-Object {
    Copy-ImageToOrganizedFolder -Path $_.FullName
    Start-Sleep -Milliseconds 2000
}

It’s entirely possible that the Copy-ImageToOrganizedFolder command accepts pipeline input, which might eliminate the need for the ForEach-Object loop (you might be able to just pipe Get-ChildItem straight to Copy-ImageToOrganizedFolder.) I’m not sure what the purpose of the 2-second sleep is inside the loop, so I left it alone.

Both seem to work, but prompts me for Values to supply to the property… :-/

In that case, I’d need to see this Copy-ImageToOrganizedFolder command. Try running these commands, and paste the output back here:

Get-Command Copy-ImageToOrganizedFolder

Get-Command Copy-ImageToOrganizedFolder -Syntax

CommandType Name Definition


Function Copy-ImageIntoOrganizedFolder …

PS C:\Windows\System32> Get-Command Copy-ImageIntoOrganizedFolder -Syntax
Copy-ImageIntoOrganizedFolder [-Path] <String[]> [-Property] <String[]> [-Filter <String>] [-Include <String[]>] [-Excl
ude <String[]>] [-Recurse] [-HideProgress] [-Verbose] [-Debug] [-ErrorAction <ActionPreference>] [-WarningAction <Actio
nPreference>] [-ErrorVariable <String>] [-WarningVariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>]
Copy-ImageIntoOrganizedFolder [-Path] <String[]> [-ScriptBlock] <ScriptBlock[]> [-Filter <String>] [-Include <String[]>
] [-Exclude <String[]>] [-Recurse] [-HideProgress] [-Verbose] [-Debug] [-ErrorAction <ActionPreference>] [-WarningActio
n <ActionPreference>] [-ErrorVariable <String>] [-WarningVariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>
]

OK, looks like it’s actually called Copy-ImageIntoOrganizedFolder; with the proper name, I was able to find the PSImageTools module via a web search. This command requires you to specify either the -Property or -ScriptBlock parameters, which it uses to create new child folders of Path. By the looks of it, you wouldn’t pipe get-childItem into this command, because it calls Get-ChildItem itself. Instead, you would do something like this:

Copy-ImageIntoOrganizedFolder -Path 'C:\Photos' -Include '*.jpg' -Property 'SomePropertyName'

On a side note, this function has nothing to do with creating a Zip file. It just makes new folders and copies files into them.

There are ways of creating zip files with the .NET Framework and PowerShell, but how you accomplish that will depend on what versions of PowerShell and .NET you need to support. If you’re running PowerShell 4.0 (or PowerShell 3.0 with .NET Framework 4.5 installed), you can use the [System.IO.Compression.ZipFile] class to make things fairly simple. For example, to zip up an entire folder, you really only need a few lines:

Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop

$folderPath = "C:\Photos"
$zipFile = "$home\Documents\Photos.zip"

[System.IO.Compression.ZipFile]::CreateFromDirectory($folderPath, $zipFile)