i have a huge amount of data which has Filenames with Unsupported Characters since i wanna move these Files to a different Location which is kinda impossible without renaming those. When running my code he gives error that he kind of cant find the Document he wants to rename Thanks in advance for any assistance.
function AdjustFilename {
param (
[String]$Path
)
if ($Path.Chars($Path.Length - 1) -ne '\') { $Path = $Path + '\' }
$filelist = get-ChildItem -LiteralPath $path -Recurse -File
foreach ($filename in $filelist) {
[String]$newfilename = $filename
$newfilename = $newfilename.Replace('?', '').Replace('/', '').Replace('\', '').Replace('{', '').Replace('}', '').Replace('<', '').Replace('>', '').Replace('|', '').Replace(':', '').Replace('*', '')
$fullpath = $filename.Fullname
if ("$filename" -ne "$newfilename") {
rename-item -LiteralPath $fullpath -NewName $newfilename
}
}
$pathlist = get-ChildItem -LiteralPath $path -Recurse -Directory
foreach ($subpath in $pathlist) {
AdjustFilename "$($Path)$($subpath)"
}
}
AdjustFilename "C:\Temp\"