Forum Discussion
manny213
Nov 08, 2024Brass Contributor
Remove characters from a file name
Hi everyone I have a bunch of CSV files in a folder that need to be cleaned up. Both the file name and file contents have unneeded apostrophes. I need the apostrophes removed from the file name on...
- Nov 08, 2024
Hi manny213 ,
A simple one-liner can handle this.
Get-ChildItem -Path "D:\Data\Temp\Forum" | ForEach-Object { Rename-Item -Path $_.FullName -NewName "$($_.Name.Replace("'", ''))"; }Example
Cheers,
Lain
LainRobertson
Nov 09, 2024Silver Contributor
Hi manny213 ,
The error is telling you that a file, for which we can only see the partial path of "C:\Users\Me...eries A (D).csv", is in use by another process. You cannot rename a file (most of the time) when it's being used by another process.
There are ways of finding which process has a lock on a file, however, none of them are short explanations. Given the error is referring to a CSV file, I'd be inclined to ensure you have closed all instances of applications like Excel, though it could be anything from a system process to a scheduled task that has a lock on the file.
Cheers,
Lain
three3f
Nov 09, 2024Copper Contributor
ok