RyterINC
RyterINC

Reputation: 119

How to loop through files and exclude specific file types

So I'm new to powershell development and writing a script that works with zip files. I can zip everything in a folder just fine, but what I'm really trying to do is loop through the directory, if there is a file with a certain extension, so let's say .txt, then it won't zip that file. I know about 3rd party extensions but I don't want to rely on those since I plan on letting other people use these scripts.

Thanks for any input!

Upvotes: 1

Views: 2327

Answers (1)

alroc
alroc

Reputation: 28204

There's no need to "loop through" anything; use the -exclude parameter for get-childitem to exclude any file with the .txt extension. Then pass the resulting collection of files to whatever is doing your zipping.

get-childitem -Exclude *.txt

Upvotes: 2

Related Questions