2

I must copy a file names as follow

  $filename = "Sport.EL#15.csv.[]"

into another folder.

if I use

  copy-item -force Sport.EL#15.csv.[] $dest_path 

it doesn't work.

since I do that:

  foreach ($f in Get-ChildItem $pathfile | Where {!$_.PsIsContainer} | Where {$_.Name -match $filename}){....}

and the error is

  Bad argument to operator '-match': parsing "Sport.EL#15.csv.[]" - Unterminated [] set..

I think the problem is the [] in the filename. how can I workaround?

1 Answer 1

7

try use:

copy-item -literalpath $filename $dest_path 

Edit after comment:

to resolve the -match issue try:

 Where {$_.Name -match [regex]::escape($filename)}

-match take a regular expression value and you need to escape each special character used in regex language to avoid problems like this.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.