0

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?

2
  • What is $FromPath set to? Commented Feb 14, 2014 at 15:42
  • $FromPath can be any number of paths. I have verified that all paths are valid and exist. Commented Feb 14, 2014 at 15:58

3 Answers 3

1

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 | ...
Sign up to request clarification or add additional context in comments.

2 Comments

Well, how would I make sure to just get files of just pdb and .dll? Should I just get rid of the pretense and just toss in the list of files?
Well, that is as good as an answer for this as I am going to get. Thanks.
1

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.