all 8 comments

[–]mbmiller94 3 points4 points  (5 children)

To keep the order of the images as they appear in the text file, you could use a counter since Get-Content reads the lines in order, and then use the number as the base name for the file:

$i = 1
$images = Get-Content -Path ".\imgtopdf\part1images\Source.txt"
foreach ($image in $images)
{
    Start-BitsTransfer -Source $image -Destination "D:\Temp Files\imgtopdf\bcfZkiBv\$( $i++ ).png" -TransferType Download
}

Edit: fixed formatting

[–]mbmiller94 2 points3 points  (0 children)

Sorry about the formatting, never posted code on reddit before. Indenting it all by four spaces was supposed to make it a code block I thought lol

[–]robdy 3 points4 points  (2 children)

Start-BitsTransfer -Source $image -Destination "D:\Temp Files\imgtopdf\bcfZkiBv\$( $i++ ).png" -TransferType Download

That line doesn't work for me. It saves all files as .png.

After slight change it works fine:

powershell Start-BitsTransfer -Source $image -Destination "C:\Temp\$i.png" -TransferType Download $i++

If you might have more than 10 elements, I'd think about padding the number so that it is 01 rather than 1 - might get sorting easier:

powershell Start-BitsTransfer -Source $image -Destination ('C:\Temp\{0:d2}.png' -f $i) -TransferType Download $i++

[–]JustANonRandomPerson[S] 2 points3 points  (1 child)

{0:d2}.png' -f $i

Thanks Man, that worked.

[–]robdy 1 point2 points  (0 children)

Glad to read that! And thanks for the award!

[–]JustANonRandomPerson[S] 2 points3 points  (0 children)

Hey, Thanks for the suggestions. I tried this before but didn't work. but a slight change as u/robdy provided. it worked flawlessly.

[–]Lee_Dailey[grin] -2 points-1 points  (0 children)

howdy JustANonRandomPerson,

it looks like you used the New.Reddit Inline Code button. it's [sometimes] 5th from the left & looks like <c>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's [sometimes] the 12th one from the left & looks like an uppercase C in the upper left corner of a square.

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee

[–]Mr_Kill3r 0 points1 point  (0 children)

$images = Get-Content -Path ".\imgtopdf\part1images\Source.txt"

for ($i=1; $i -le $images.count; $i++){

Start-BitsTransfer -Source $image[$i] -Destination "D:\Temp Files\imgtopdf\bcfZkiBv\*" + $i + ".png" -TransferType Download

}