-1

I have a friend with a video on my computer. The path is

C:\Users\Me\Videos\Tonys Videos\Dinosaur [1080p]\

In the Dinosaur movie folder is an "asset" folder, which contains a few .gif,.jpg and .png files. I wanted to learn a little bit about Powershell so I changed the directory with...

cd "C:\Users\Me\Videos\Tonys Videos\Dinosaur ``[1080p``]\assets"

The (`) was needed for the special bracket characters & the quotations for the space in the folder named "Tonys Videos". I can type in Get-ChildItem & the entire list will populate just fine, but I run into errors when I attempt to use the exclude flag (whether a single or multiple strings are "excluded" it still shows no output.

I ran another test, where I copied the "assets" folder to "Tonys Videos" (so the grave-accent would be omitted and everything ran just fine. I'm using PS v2.0 but that really shouldn't change much. My question is why didn't the "Get-ChildItem -exclude" work with the grave accents?

In response to the comment, this is my attempt with Get-ChildItem

Get-ChildItem "C:\Users\Me\Videos\Tonys Videos\Dinosaur ``[1080p``]\assets" -Exclude *.jpg,*png

I have tested this same format (as stated above) in the "Tonys Videos" folder and it worked just fine. Thanks for your continued assistance.

JoeDaHobo
  • 25
  • 1
  • 1
  • 5

2 Answers2

0

When there are special keys in the path use Get-ChildItem -LiteralPath "YourPath". With -LiteralPath you don't need the (`).
What do you write by the exclude?

For me this one works:

Get-ChildItem -Path "C:\temp\``[TEST``]\*.*" -Exclude *.jpg,*.png


You need the \*.* that you can exclude something. With Get-ChildItem -LiteralPath you can't use \*.*.

Can you use this?

Get-ChildItem -Path "C:\temp\``[TEST``]" | Where-Object -FilterScript {$_.Name -notlike "*.jpg" -and $_.Name -notlike "*.png"}


Maybe an other user knows why the exclude don't work.

Patrick
  • 2,128
  • 16
  • 24
  • For exclude I used -exclude *.png,*.jpg The literal path for some reason didn't take into account the -exclude flag (or -Exclude, tried both if it makes a difference) – JoeDaHobo Aug 23 '14 at 20:37
  • I'll also add that `GCI -Path` option with `*.*` at the end does not include folders, that will only list files. – TheMadTechnician Aug 25 '14 at 20:42
  • Pipe-lining the objects into a FilterScript did the trick. Thanks everyone – JoeDaHobo Aug 26 '14 at 11:23
0

You can also include the string in single quotes which won't attempt to expand or interpret the strings contents. Note that variables won't expand either.

Matt
  • 45,022
  • 8
  • 78
  • 119