Powershell 檢查文件類型 (Powershell check file type)


問題描述

Powershell 檢查文件類型 (Powershell check file type)

我正在編寫一個修改文件夾中圖像的腳本,在大多數情況下,我將 Get‑ChildItem 與目錄一起使用。

所以我我目前正在做一個名為

$fileExtension = [IO.Path]::GetExtension($files[$counter].Name)

的變量,其 if 語句類似於:

if($fileExtension ‑eq '.png' or
    $fileExtensiono ‑eq '.jpg'. . . )

有更好的方法嗎?如果文件是圖像,我真的希望它執行這個修改圖像的功能,一個文件夾可以包含其他項目,例如一個 zip,如果它拾取它會導致腳本崩潰。


參考解法

方法 1:

try Something like this:

get‑childitem 'c:\temp\*' ‑file ‑include '*.png', '*.jpg'

(by l3l00Esperento57)

參考文件

  1. Powershell check file type (CC BY‑SA 2.5/3.0/4.0)

#file-type #powershell






相關問題

PHP - 只讀電子表格文件類型? (PHP - Read-Only spreadsheet filetype?)

文件類型指示符,sys/stat.h st_mode 常規文件代碼值 (File type indicator, sys/stat.h st_mode regular file code value)

文件類型圖標未在 Visual Studio 中更新 (File Type Icon not updating in Visual Studio)

在哪裡可以獲得 mime.types 文件的副本? (Where to get a copy of mime.types file?)

當名稱中包含“build”時,vim xml 文件類型設置為“ant” (vim xml file type set as "ant" when name has 'build' in it)

PHP:文件上傳不驗證文件類型 (PHP: File upload not verifying file type)

從文件類型建議文件擴展名 (Suggest file extension from file type)

從 C# 應用程序打開文件時,是否值得在註冊表中查找默認應用程序? (Is it worth it to lookup the default application in the registry when opening a file from a C# application?)

返回音頻文件類型列表 (Returning a list of audio filetypes)

Powershell 檢查文件類型 (Powershell check file type)

為什麼我的自定義 CSS 文件類型不顯示供 iOS 模擬器上的 FilePick 選擇? (Why is my custom CSS filetype not displaying for selection with FilePick on iOS Simulator?)

如何將自定義上下文菜單添加到特定類型的所有擴展(例如所有視頻文件) (How can I add a custom context menu to all extensions of a particular type (e.g. all video files))







留言討論