Powershell: backslash at end of string filepath in CSV stopping replacement : I have a CSV file with a list of full file paths. It looks something like this:

C:\Folder1\Subfolder1\file1.txt  
C:\Folder1\Subfolder2\file2.txt  
C:\Folder1\Subfolder3\file3.txt  

What I'm trying to do is to remove the "C:\Folder1\" from the string so that I'm only left with:

Subfolder1\file1.txt  
Subfolder2\file2.txt  
Subfolder3\file3.txt  

I came up with the following script:

    (Get-Content c:\test.csv) | 
        % {$_.replace('C:\\Folder1\\','')}

When I run this, the replace does not work at all.

If I leave the "\\\\" off the end of the path, it works except it keeps a backslash in front of the Subfolder name:

\Subfolder1\file1.txt  
\Subfolder2\file2.txt  
\Subfolder3\file3.txt  

I have tried a number of different methods to get this to work, including adding more backslashes to escape the backslash and changing the single quotes to double-quotes around the string I want to replace, but nothing is working.

Would someone point me in the right direction of what I am doing wrong?

Thanks!


