taps
May 17, 2021, 6:06am
1
Hello , I used this code, but no work if my computer locked. can you please advise me how to solve the problem? I’m beginner. Thank you.
$Path = "c:\Automat\logs"
$Server = "C:\Users\user\image"
Get-ChildItem ($Path+"\*.*") -Recurse -Exclude *.tif | % {
Copy-Item -Path $_.FullName -Destination '\\server01\temp\' -Force
}
Get-ChildItem ($Path+"\*.tif") | %{
$file = new-object System.Drawing.Bitmap($_.FullName);
$file.Save(( Join-Path $Server ($_.Name -replace "tif", 'jpg') ),"JPEG");
$file.dispose();
sleep(5)
Remove-Item $_.FullName
}
Olaf
May 17, 2021, 1:19pm
2
I thought we already switched to another approach!?
What about this:
Hmmm … I’d start with formatting the code nicely. It makes it easier to read and to understand …
$Path = "c:\files\images\"
Get-ChildItem ($Path + "\*.tif") |
ForEach-Object {
$file = new-object System.Drawing.Bitmap($_.FullName)
$file.Save(( Join-Path "\\server\upload\" ($_.Name -replace "tif", 'jpg') ), "JPEG")
$file = ""
}
Get-ChildItem ($Path + "\*.*") -Recurse |
Remove-Item -Force
Then I’d start to try to simplify my code. If I’m not wrong you want …
Regardless of that - without more detailed information we are pretty much unable to give a meaningful recommendation. None of the code is actually influenced by the lock state of a computer.
Olaf
May 17, 2021, 1:50pm
4
taps:
I need copy item from my pc to \server01\temp (without tif images)
That shouldn’t be that much of a challenge, right?
taps:
Images (format tif) save as jpg to C:\Users\user\image
Do you mean to rename or to convert them? Renaming is easy with the cmdlet Rename-Item.
If you want to convert them you will have to use external tools like IrfanView or something similar.
taps
May 17, 2021, 2:04pm
5
I need convert, because I use jpg on website to lightbox
Olaf
May 17, 2021, 2:31pm
6
So you will have to use an external tool of your choice. As far as I know there is no builtin function to convert one picture format into another.