Question
How can I edit this script so that it only changes the 'Last Modified Date' in the files that it replaces the 'forttester' string in?
How can I edit this script so that it only changes the 'Last Modified Date' in the files that it replaces the 'fort\tester' string in? Right now it modifies the date of all files. Also, I want to replace the string 'fort\tester' with 'fort\success' but it is currently adding an extra slash in 'fort\success' (so it inserts 'fort\\success' instead when it should be just 'fort\success'
$filePath = "C:\Users\Desktop\*.bat" $dateChanged = $false
# Get the files from the folder and iterate using Foreach Get-ChildItem $filePath -Recurse | ForEach-Object { $originalContent = Get-Content $_ $modifiedContent = $originalContent -ireplace 'fort\\tester','fortress\\success'
# Check if the content was modified if ($originalContent -ne $modifiedContent) { $modifiedContent | Set-Content $_ $dateChanged = $true } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started