Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell check file type

I am working on a script that modifies images in a folder, for the most part, it is done I use Get-ChildItem with the directory.

So what I am currently doing is making a variable called

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

with an if statement that is like:

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

Is there a better way of doing this? I really want it to execute this function that modifies images if the file is an image, a folder could contain other items such as a zip which will crash the script if it picks up on it.

like image 541
l3l00 Avatar asked Feb 02 '26 09:02

l3l00


1 Answers

try Something like this:

get-childitem 'c:\temp\*' -file -include '*.png', '*.jpg'
like image 102
Esperento57 Avatar answered Feb 05 '26 09:02

Esperento57



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!