Daniel Groß
Daniel Groß

Reputation: 37

Powershell Path Replacement

Hey it's me again with my paths :D

I write my Paths into a TXT-File.

Ex:

C:\Ex\am\ple\path.txt  
C:\Ex\am\ple\file.txt  
C:\Ex\am\ple\text.txt 

Now I want to replace the "*.txt" at the end of every Path.

I tried the following:

(Get-Content ".\MYPATHS.txt") | Foreach-Object {$_ -replace "\*.txt"}| Set-Content ".\MYPATHS.txt"

Where's is my fault?

Upvotes: 0

Views: 79

Answers (1)

Jaqueline Vanek
Jaqueline Vanek

Reputation: 1133

k, if you need just the path(without the files):

'C:\Ex\am\ple\path.txt', 'C:\Ex\am\ple\file.txt' | Split-Path -Parent

the list above

'C:\Ex\am\ple\path.txt', 'C:\Ex\am\ple\file.txt'

replaces 'Get-Content'. Output:

C:\Ex\am\ple
C:\Ex\am\ple

Upvotes: 3

Related Questions