Question:
I often see PowerShell commands that use paths that use a double asterisks:
1 2 |
Copy-Item c:\source\** d:\target |
The example may be wrong, as I don’t understand POSH that well yet. But I do see examples using the **
in paths. What does it mean?
Answer:
Actually, I believe the above answer is wrong.
Assume we have the following directory structure:
dbl_wc (top level)
--one_level_in
--aa.txt
--one_level_in1
--bb.txt
--deeper_dir
--abc.txt
Copy-Item .\dbl_wc\**\*.txt copy_target -Force
Will only look for *.txt in any directory under .\dbl_wc. And it won’t look in sub-directories (so for example .\dbl_wc\one_level_in1\deeper_dir). So it will get both aa.txt and bb.txt, but not abc.txt. It would also not get any .txt file directly under dbl_wc
Essentially, the ** stands for a directory-wildcard, but not recursive.
EDIT: just tested it with *, and it does the same thing (so Copy-Item .\dbl_wc\*\*.txt copy_target -Force
does the exact same thing as above)