Powershell - excluding folders from string

Viewed 39

I have a huge directory (several thousand folders), like so:

...\94000\abc\def\hig
...\95000\abc\def\hig 
...\96000\abc\def\hig
...\97000\abc\def\hig
...

So there is one part of the path that alternates but the rest of the folder structure is the same. Also lots of subfolders under abc and def, etc.

What I need to do is copy a specific file from let's say the folder "hig".

I am quite new to Powershell but managed to put together the following:

$destination = "C:\Users\etc..."
   $source = "B:\94000"
   Get-ChildItem $source -Filter "LIVE*.docx" -File -Recurse | Foreach {
          Copy-Item $_.FullName $destination
   }

I know it is very basic but it actually works. The problem is that it is quite slow, give the number of folders to sift through.

Is there any way to expedite things? I was thinking to make the script skip folders that I know do not contain the file I need.

I was also wondering if I could use a wildcard in the path so I could define the exact folders, like so: \9*000abc\def\hig

But couldn't make either work.

Any idea is very much appreciated!

3 Answers
Related