create account

PowerShell Hack: How to replace text in multiple files 💪 by vikisecrets

View this thread on: hive.blogpeakd.comecency.com
· @vikisecrets ·
$1.44
PowerShell Hack: How to replace text in multiple files 💪
PowerShell Hack: Mit diesem PowerShell-Skript kannst du Text in mehreren Dateien ersetzen.

Ich habe ein kleines PowerShell-Skript für Windows geschrieben, um Text in einem ganzen Verzeichnis und dessen Unterverzeichnissen zu ersetzen.

Das kann manchmal ganz praktisch sein, wenn man zum Beispiel in einem ganzen Ordner mit html-Dateien, etwas in allen Dateien ersetzen möchte und das Projekt nicht in Visual Studio geöffnet hat.

Das folgende Skript ersetzt im aktuellen Verzeichnis und dessen Unterverzeichnissen in allen Textdateien (*.txt) den Text "search" mit "substitute".

```
$files = Get-ChildItem . *.txt -rec
foreach ($file in $files)
{
(Get-Content -Raw $file.PSPath) -replace "search", "substitute" |
Set-Content $file.PSPath
}
```

Vorsicht: Bevor man das Skript verwendet, empfehle ich das angepasste Skript in einem Testordner zu testen und ein Backup des Ordners zu erstellen, auf dem man das Skript anwenden möchte.

![powershellhero1.jpg](https://files.steempeak.com/file/steempeak/vikisecrets/wK4Bxrm3-powershell-hero-1.jpg)

## English ##

*PowerShell Hack: With this PowerShell script you can replace text in multiple files.*

*I wrote a small PowerShell script for Windows to replace text in an entire directory and its subdirectories.*

*This can sometimes come in handy if, for example, you want to replace something in a folder of html files and you don't have the project open in Visual Studio.*

*The following script replaces the text "search" with "substitute" in the current directory and its subdirectories in all text files (*.txt).*

```
$files = Get-ChildItem . *.txt -rec
foreach ($file in $files)
{
(Get-Content -Raw $file.PSPath) -replace "search", "substitute" |
Set-Content $file.PSPath
}
```

*Caution: Before using the script, I recommend testing the customized script in a test folder and making a backup of the folder where you want to apply the script to.*

*Live your Secrets and Steem Prosper* 🔥

xx Viki @vikisecrets

Blog post: [Text in mehreren Dateien (in einem ganzen Verzeichnis) mit der Windows PowerShell ersetzen](https://virtualnet.at/weblog/250)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 10 others
👎  ,
properties (23)
authorvikisecrets
permlinkpowershell-hack-how-to-replace-text-in-multiple-files
categoryhowto
json_metadata{"app":"steempeak/2.2.8","format":"markdown","tags":["howto","powershell","technology","windows","deutsch","palnet"],"users":["vikisecrets"],"links":["/@vikisecrets","https://virtualnet.at/weblog/250"],"image":["https://files.steempeak.com/file/steempeak/vikisecrets/wK4Bxrm3-powershell-hero-1.jpg"]}
created2020-01-21 12:07:33
last_update2020-01-21 12:07:33
depth0
children11
last_payout2020-01-28 12:07:33
cashout_time1969-12-31 23:59:59
total_payout_value0.734 HBD
curator_payout_value0.706 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,105
author_reputation1,203,372,732,503,092
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,606,277
net_rshares6,478,726,475,460
author_curate_reward""
vote details (76)
@avare ·
$0.03
!COFFEEA $trdo
For you
👍  ,
properties (23)
authoravare
permlinkre-vikisecrets-2020121t174530949z
categoryhowto
json_metadata{"tags":["howto","powershell","technology","windows","deutsch","palnet"],"app":"esteem/2.2.2-mobile","format":"markdown+html","community":"esteem.app"}
created2020-01-21 14:44:54
last_update2020-01-21 14:44:54
depth1
children1
last_payout2020-01-28 14:44:54
cashout_time1969-12-31 23:59:59
total_payout_value0.013 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length22
author_reputation30,667,607,216,522
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,610,990
net_rshares172,121,362,135
author_curate_reward""
vote details (2)
@trendotoken ·
Congratulations @avare, you successfuly trended the post shared by @vikisecrets!
@vikisecrets will receive <b>0.13987688</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) & @avare will get <b>0.09325125</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation in 3 Days from Post Created Date!

<b>"Call [TRDO](https://steem-engine.com/?p=history&t=TRDO), Your Comment Worth Something!"</b>
---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-avare-re-vikisecrets-2020121t174530949z-20200121t144502880z
categoryhowto
json_metadata{"tags":["comments-scot","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2020-01-21 14:45:03
last_update2020-01-21 14:45:03
depth2
children0
last_payout2020-01-28 14:45:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length618
author_reputation5,546,209,053,433
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,610,995
net_rshares0
@bitandi ·
$0.03
Cool 👍
👍  
properties (23)
authorbitandi
permlinkre-vikisecrets-2020121t175715511z
categoryhowto
json_metadata{"tags":["howto","powershell","technology","windows","deutsch","palnet"],"app":"esteem/2.2.2-mobile","format":"markdown+html","community":"esteem.app"}
created2020-01-21 16:57:15
last_update2020-01-21 16:57:15
depth1
children0
last_payout2020-01-28 16:57:15
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6
author_reputation447,713,177,760,555
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,615,372
net_rshares166,443,794,524
author_curate_reward""
vote details (1)
@coffeea.token ·
[![coffeea](http://c0ff33a.uk/coffeea.jpg)](http://bit.ly/2YbNaET)  Lucky you @vikisecrets here is your COFFEEA, view all your tokens at [steem-engine.com](https://steem-engine.com/) [Vote for c0ff33a as Witness](http://bit.ly/2YbNaET)
properties (22)
authorcoffeea.token
permlinkre-powershell-hack-how-to-replace-text-in-multiple-files-20200121t183224z
categoryhowto
json_metadata"{"app": "beem/0.21.1"}"
created2020-01-21 18:32:27
last_update2020-01-21 18:32:27
depth1
children0
last_payout2020-01-28 18:32:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length235
author_reputation4,292,084,626,291
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,617,907
net_rshares0
@germanbot ·
Du hast ein Upvote von mir bekommen, diese soll die Deutsche Community unterstützen. Wenn du mich unterstützten möchtest, dann sende mir eine Delegation. Egal wie klein die Unterstützung ist, Du hilfst damit der Community. DANKE!

properties (22)
authorgermanbot
permlinkre-powershell-hack-how-to-replace-text-in-multiple-files-20200121t121309z
categoryhowto
json_metadata"{"app": "beem/0.20.19"}"
created2020-01-21 12:13:15
last_update2020-01-21 12:13:15
depth1
children0
last_payout2020-01-28 12:13:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length231
author_reputation6,584,993,625,435
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,606,441
net_rshares0
@investinthefutur ·
@mima2606 denkt du hast ein Vote durch @investinthefutur verdient! ----> [Wer ist investinthefutur ?](https://steemit.com/deutsch/@investinthefutur/wer-ist-investinthefutur)<br>@mima2606 thinks you have earned a vote of @investinthefutur !----> [Who is investinthefutur ?](https://steemit.com/deutsch/@investinthefutur/wer-ist-investinthefutur)
properties (22)
authorinvestinthefutur
permlinkre-powershell-hack-how-to-replace-text-in-multiple-files-20200121t132029z
categoryhowto
json_metadata"{"app": "beem/0.22.0"}"
created2020-01-21 13:20:30
last_update2020-01-21 13:20:30
depth1
children0
last_payout2020-01-28 13:20:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length344
author_reputation135,729,607,290,395
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,608,341
net_rshares0
@investinthefutur ·
@querdenker denkt du hast ein Vote durch @investinthefutur verdient! ----> [Wer ist investinthefutur ?](https://steemit.com/deutsch/@investinthefutur/wer-ist-investinthefutur)<br>@querdenker thinks you have earned a vote of @investinthefutur !----> [Who is investinthefutur ?](https://steemit.com/deutsch/@investinthefutur/wer-ist-investinthefutur)
properties (22)
authorinvestinthefutur
permlinkre-powershell-hack-how-to-replace-text-in-multiple-files-20200122t015744z
categoryhowto
json_metadata"{"app": "beem/0.22.0"}"
created2020-01-22 01:57:45
last_update2020-01-22 01:57:45
depth1
children0
last_payout2020-01-29 01:57:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length348
author_reputation135,729,607,290,395
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,626,614
net_rshares0
@jaffgrah ·
i hope i can be good in programing
👎  , ,
properties (23)
authorjaffgrah
permlinkre-vikisecrets-q4favw
categoryhowto
json_metadata{"tags":["howto"],"app":"steempeak/2.2.8"}
created2020-01-21 20:19:18
last_update2020-01-21 20:19:18
depth1
children0
last_payout2020-01-28 20:19:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation-237,855,663,048
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,620,413
net_rshares-47,987,367,539
author_curate_reward""
vote details (3)
@mima2606 ·
$0.03
Echt cool, wusste gar nicht dass du auch Skripte schreibst. LG Michael 
!invest_vote
👍  
properties (23)
authormima2606
permlinkre-vikisecrets-q4gkx9
categoryhowto
json_metadata{"tags":["howto"],"app":"steempeak/2.2.8"}
created2020-01-21 13:17:36
last_update2020-01-21 13:17:36
depth1
children0
last_payout2020-01-28 13:17:36
cashout_time1969-12-31 23:59:59
total_payout_value0.013 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length84
author_reputation178,748,423,282,323
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,608,249
net_rshares170,863,045,575
author_curate_reward""
vote details (1)
@querdenker ·
Sehr interessant. Versuche mir nur gerade mal einen Use Case vorzustellen. Yours Querdenker !invest_vote
properties (22)
authorquerdenker
permlinkre-vikisecrets-q4hiae
categoryhowto
json_metadata{"tags":["howto"],"app":"steempeak/2.2.8"}
created2020-01-22 01:55:06
last_update2020-01-22 01:55:06
depth1
children0
last_payout2020-01-29 01:55:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length104
author_reputation8,990,783,240,010
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,626,568
net_rshares0
@trendotoken ·
Congratulations @vikisecrets, your post successfully recieved <b>0.13987688</b> [TRDO](https://steem-engine.com/?p=history&t=TRDO) from below listed TRENDO callers:<br>

>	<sup>@avare earned : **0.09325125** [TRDO](https://steem-engine.com/?p=history&t=TRDO) curation</sup> 

---
<sup>To view or trade TRDO go to [steem-engine.com](https://steem-engine.com/?p=market&t=TRDO)
Join [TRDO Discord Channel](https://discord.gg/wySP8T9) or Join [TRDO Web Site](http://www.trendotoken.info/)</sup>
properties (22)
authortrendotoken
permlinkre-vikisecrets-powershell-hack-how-to-replace-text-in-multiple-files-20200124t125130549z
categoryhowto
json_metadata{"tags":["trdo","trendo-bot"],"app":"comments-scot/1.1","format":"markdown"}
created2020-01-24 12:52:33
last_update2020-01-24 12:52:33
depth1
children0
last_payout2020-01-31 12:52:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length490
author_reputation5,546,209,053,433
root_title"PowerShell Hack: How to replace text in multiple files 💪"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,721,202
net_rshares0