Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:48:05+00:00 2026-06-07T04:48:05+00:00

From this posting, I managed to replace a string in a directory’s subfiles with

  • 0

From this posting, I managed to replace a string in a directory’s subfiles with Powershell on Windows XP.

foreach ($f in gci -r -include "*.bat") 
    { (gc $f.fullname) |
       foreach { $_ -replace "D:","C:\path" }  |
       sc $f.fullname 
    }

Unfortunately, a few exceptional cases required a “C:\\” rather than a “C:\”.

I attempted to use the following command to fix this problem (replacing “C:\path\\” with “C:\\path\\”), but it fails:

foreach ($f in gci -r -include "*.bat") 
    { (gc $f.fullname) |
       foreach { $_ -replace "C\path\\","C:\\path\\" }  |
       sc $f.fullname 
    }

The error is:

Invalid regular expression pattern: C:\path\\

I attempted several variants in an effort to circumvent the problem, but all produce the same error (replacing line #3 above):

foreach { $_ -replace "C:\path\\\\","C:\\path\\" } |
foreach { $_ -replace 'C:\path\\',"C:\\path\\" } |
foreach { $_ -replace "`C:\path\\","C:\\path\\" } |
foreach { $_ -replace 'C:\path\\\\',"C:\\path\\" } |

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:48:06+00:00Added an answer on June 7, 2026 at 4:48 am

    For repalcing replacing “C:\path\” with “C:\\path\\”

    use

    $_ -replace "c:\\path\\\\","c:\\path\\"
    

    The Match pattern is regex and ‘\’ needs to be escaped with an ‘\’.
    The replace string is just a string, no needs escape characters

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm cross-posting this from the wordpress section, b/c I think the problem lies more
Note: I am cross-posting this from App Engine group because I got no answers
I am trying to integrated linkedIn using this question answer Posting LinkedIn message from
I'm posting this JSON from a form page <script src=http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js type=text/javascript></script> <script type=text/javascript> function
My original question I've managed to answer by cobbling other answers together from this
I'm porting some code from Python 2 to 3. This is valid code in
I'm copying a range from the page and pasting it back elsewhere, but this
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.
From this link the author suggested: table.setWidth(100%, true); table.setColumnWidth(nameColumn, 35.0, Unit.PCT); table.setColumnWidth(addressColumn, 65.0, Unit.PCT);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.