Reputation: 9737
This powershell script isn't working for me...
gci -path $FromPath -Include ("*.dll", "*.pdp") | ? {$_.Name -match "CSLib|CBCore|Cn|CFramework"} | foreach{write-host("Do I have the files here? : "+ $_.Fullname + " -destination" + $ToPath) }
You can basically break it down into three parts...
gci -path $FromPath -Include ("*.dll", "*.pdp") |
? {$_.Name -match "CSLib|CBCore|Cn|CFramework"}
foreach{write-host("Do I have the files here? : "+ $_.Fullname + " -destination" + $ToPath) }
Each of those should work individually. I replaced my actual move script with a command just to write out the files. But that doesn't seem to work either. Not sure what I am missing?
Upvotes: 0
Views: 74
Reputation: 2772
As Adil points out, you have to have a '*' on the path or -recurse parameter for the -include clauses to work in the way required.
There is a good Microsoft blog post on the whole subject here:
http://blogs.msdn.com/b/powershell/archive/2006/04/25/583260.aspx
Upvotes: 0
Reputation: 6605
What Efran said above will work but not for the reason he stated. You can use -include the way you did but it would not work the way you think. Here are a few examples to explain:
This returns nothing
PS C:\Users\Adil> gci c:\temp\ -include *.xml,*.png
This returns any xml or png file 'under' c:\temp. Note use of '*'
PS C:\Users\Adil> gci c:\temp\* -include *.xml,*.png
Directory: C:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/13/2014 7:30 PM 3052 a.xml
-a--- 4/1/2013 9:22 PM 15550 Location Settings_procmon2.png
I am not specifying '*' here, but using -recurse, therefore I will get all files with the extensions I 'included' not only under C:\temp but also for subdirectories
PS C:\Users\Adil> gci c:\temp -recurse -include *.xml,*.png
Directory: C:\temp\2013.01\09
Mode LastWriteTime Length Name
---- ------------- ------ ----
----- 8/25/2013 1:17 PM 226095 IMG_0648.PNG
-a--- 8/25/2013 3:37 PM 396860 tablet.PNG
Directory: C:\temp\2013.04
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 4/14/2013 11:40 PM 20513 Bitcn.xml
-a--- 4/14/2013 11:39 PM 18038 Bitcn1.png
Upvotes: 1
Reputation: 6454
I believe you are using -Include
in a way which is not what you intended; in fact, -Include
is applied to the paths and not to the files.
You could just avoid using -Include
in your first script block:
gci -path $FromPath *.dll, *.pdp | ...
Upvotes: 1