Search

PowerShell 2.0 - Cannot get "Copy-Item" to copy files if files have brackets in their filename by CJ Manning

Active

1
0
Sign in
to vote
Type: Bug
ID: 776371
Opened: 1/11/2013 1:02:11 PM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug


Basically what I'm trying to do is:

I'm pulling information from a .csv spreadsheet that contains a list of files that I need. The problem is, the directory they are in contains 16,000+ files! I only need around 4600 of them (as the spreadsheet column only contains that many). I've actually gotten all that part of the code figured out... but where I'm running into issues is when it gets to the "Copy-Item" portion of my code. It runs fine until it hits files that have brackets as part of the filename, so of course it throws errors and doesn't give me what I need. How can I fix this? Mind you, the files needing/being copied CAN'T be renamed. I'm not sure how to use "-LiteralPath" here, if that's a solution. :( Here's my code below:

$Directory = gci D:\Documents\15075_32\
$Destination = "D:\CleanReview"
$ReviewSheet = import-csv 'C:\Users\7cm\Desktop\Internal Review - Emails Removed per Attorney Request.csv'
$BaseItem = foreach($li in $ReviewSheet){$li.Base}
foreach($File in $Directory){
    $File.BaseName
foreach($Item in $BaseItem){
    if($Item -like $File.BaseName){
        $Item
            Copy-Item $File.FullName $Destination -Force
}
}
}

So as you can see, it won't copy items that are declared since the files are going to be variable. If this was a single file, or if I could easily list them as an array I could take care of this... but even -LiteralPath won't work!
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

I don't know if this issue existed previously
Reproduction Steps
 
Expected Results
I should have the list of files that are "-like" the basenames I'm comparing them to... it works for all other files except the ones with brackets. I would expect it to work despite this.
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.