Board logo

標題: power shell 問題 [打印本頁]

作者: ghostkcleung    時間: 2023-5-29 18:51     標題: power shell 問題

我想將一個 Folder 裡面,所有橫影嘅圖片,
都 Copy 晒落另一個 Folder,
問過 GPT 俾咗下面堆 PS Code 我,
但係明明啲圖片係直影,個 Dimension 都調轉咗。
  1. Add-Type -AssemblyName System.Drawing

  2. $source = "D:\photos"
  3. $destination = "D:\landscape"
  4. $count = 1

  5. Get-ChildItem -Path $source -Filter *.jpg -Recurse | ForEach-Object {
  6.     $image = [System.Drawing.Image]::FromFile($_.FullName)
  7.     if ($image.Width -gt $image.Height) {
  8.         $newName = "{0:D4}.jpg" -f $count
  9.         $newPath = Join-Path $destination $newName
  10.         Copy-Item $_.FullName -Destination $newPath
  11.         $count++
  12.     }
  13. }
複製代碼

作者: javacomhk    時間: 2023-5-29 18:56

本帖最後由 javacomhk 於 2023-5-29 10:58 編輯

powershell 嘅問題你問 Bing 嘅 AI 會好的





歡迎光臨 電腦領域 HKEPC Hardware (https://h2.hkepc.com/forum/) Powered by Discuz! 7.2