{"id":301,"date":"2017-08-06T16:46:30","date_gmt":"2017-08-06T16:46:30","guid":{"rendered":"http:\/\/www.busted.dk\/blog\/?p=301"},"modified":"2025-03-11T13:29:13","modified_gmt":"2025-03-11T11:29:13","slug":"renameremove-characters-files-folders","status":"publish","type":"post","link":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/","title":{"rendered":"Rename\/remove characters from files and folders."},"content":{"rendered":"<p>This is a powershell script that removes or renames special characters from files or folder.<\/p>\n<p>Very useful if you are going to upload a lot of files to SharePoint or OneDrive and you files contains illegal characters.<\/p>\n<p><span class=\"nv\">$folder<\/span> <span class=\"p\">=<\/span> <span class=\"s1\">&#8216;c:\\mytest&#8217;<br \/>\n<\/span><span class=\"nb\">Get-ChildItem<\/span> <span class=\"nv\">$folder<\/span> <span class=\"n\">-Recurse<\/span> <span class=\"p\">|<\/span> <span class=\"p\">?<\/span> <span class=\"p\">{<\/span><span class=\"nv\">$_<\/span> <span class=\"o\">-match<\/span> <span class=\"s1\">&#8216;%|#|_&#8217;<\/span><span class=\"p\">}<\/span> <span class=\"p\">|<\/span> <span class=\"n\">sort<\/span> <span class=\"n\">psiscontainer<\/span><span class=\"p\">,<\/span> <span class=\"p\">{<\/span><span class=\"nv\">$_<\/span><span class=\"p\">.<\/span><span class=\"n\">fullname<\/span><span class=\"p\">.<\/span><span class=\"n\">length<\/span> <span class=\"p\">*<\/span> <span class=\"p\">&#8211;<\/span><span class=\"n\">1<\/span><span class=\"p\">}<\/span> <span class=\"p\">|<\/span> <span class=\"p\">%<\/span> <span class=\"p\">{<\/span><span class=\"n\">ren<\/span> <span class=\"nv\">$_<\/span><span class=\"p\">.<\/span><span class=\"n\">FullName<\/span> <span class=\"p\">$(<\/span><span class=\"nv\">$_<\/span><span class=\"p\">.<\/span><span class=\"n\">name<\/span> <span class=\"o\">-replace<\/span> <span class=\"s1\">&#8216;%|#&#8217;<\/span> <span class=\"o\">-replace<\/span> <span class=\"s1\">&#8216;_&#8217;<\/span><span class=\"p\">,<\/span> <span class=\"s1\">&#8216; &#8216;<\/span><span class=\"p\">)}<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a powershell script that removes or renames special characters from files or folder. Very useful if you are going to upload a lot of files to SharePoint or OneDrive and you files contains illegal characters. $folder = &#8216;c:\\mytest&#8217; Get-ChildItem $folder -Recurse | ? {$_ -match &#8216;%|#|_&#8217;} | sort psiscontainer, {$_.fullname.length * &#8211;1} | &#8230; <a title=\"Rename\/remove characters from files and folders.\" class=\"read-more\" href=\"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/\" aria-label=\"Read more about Rename\/remove characters from files and folders.\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,1],"tags":[10,32],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-powershell","category-uncategorized","tag-powershell","tag-rename-special-characters"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Rename\/remove characters from files and folders. - Peter Busted<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peter\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/\"},\"author\":{\"name\":\"Peter\",\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#\\\/schema\\\/person\\\/6f1b95dddb508da8b018577701c33c9d\"},\"headline\":\"Rename\\\/remove characters from files and folders.\",\"datePublished\":\"2017-08-06T16:46:30+00:00\",\"dateModified\":\"2025-03-11T11:29:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/\"},\"wordCount\":61,\"publisher\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#\\\/schema\\\/person\\\/6f1b95dddb508da8b018577701c33c9d\"},\"keywords\":[\"powershell\",\"rename special characters\"],\"articleSection\":[\"PowerShell\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/\",\"url\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/\",\"name\":\"Rename\\\/remove characters from files and folders. - Peter Busted\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#website\"},\"datePublished\":\"2017-08-06T16:46:30+00:00\",\"dateModified\":\"2025-03-11T11:29:13+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.busted.dk\\\/blog\\\/renameremove-characters-files-folders\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/\",\"name\":\"Peter Busted\",\"description\":\"A blog about my daily work with tech and more, running since 2008\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#\\\/schema\\\/person\\\/6f1b95dddb508da8b018577701c33c9d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/#\\\/schema\\\/person\\\/6f1b95dddb508da8b018577701c33c9d\",\"name\":\"Peter\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp\",\"url\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp\",\"contentUrl\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp\",\"width\":1790,\"height\":357,\"caption\":\"Peter\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp\"},\"url\":\"https:\\\/\\\/www.busted.dk\\\/blog\\\/author\\\/peter\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Rename\/remove characters from files and folders. - Peter Busted","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/","twitter_misc":{"Written by":"Peter"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/#article","isPartOf":{"@id":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/"},"author":{"name":"Peter","@id":"https:\/\/www.busted.dk\/blog\/#\/schema\/person\/6f1b95dddb508da8b018577701c33c9d"},"headline":"Rename\/remove characters from files and folders.","datePublished":"2017-08-06T16:46:30+00:00","dateModified":"2025-03-11T11:29:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/"},"wordCount":61,"publisher":{"@id":"https:\/\/www.busted.dk\/blog\/#\/schema\/person\/6f1b95dddb508da8b018577701c33c9d"},"keywords":["powershell","rename special characters"],"articleSection":["PowerShell"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/","url":"https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/","name":"Rename\/remove characters from files and folders. - Peter Busted","isPartOf":{"@id":"https:\/\/www.busted.dk\/blog\/#website"},"datePublished":"2017-08-06T16:46:30+00:00","dateModified":"2025-03-11T11:29:13+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.busted.dk\/blog\/renameremove-characters-files-folders\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.busted.dk\/blog\/#website","url":"https:\/\/www.busted.dk\/blog\/","name":"Peter Busted","description":"A blog about my daily work with tech and more, running since 2008","publisher":{"@id":"https:\/\/www.busted.dk\/blog\/#\/schema\/person\/6f1b95dddb508da8b018577701c33c9d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.busted.dk\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.busted.dk\/blog\/#\/schema\/person\/6f1b95dddb508da8b018577701c33c9d","name":"Peter","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.busted.dk\/blog\/wp-content\/uploads\/2025\/03\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp","url":"https:\/\/www.busted.dk\/blog\/wp-content\/uploads\/2025\/03\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp","contentUrl":"https:\/\/www.busted.dk\/blog\/wp-content\/uploads\/2025\/03\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp","width":1790,"height":357,"caption":"Peter"},"logo":{"@id":"https:\/\/www.busted.dk\/blog\/wp-content\/uploads\/2025\/03\/cropped-f819f80c-bdd3-4653-87cc-89c692229010.webp"},"url":"https:\/\/www.busted.dk\/blog\/author\/peter\/"}]}},"_links":{"self":[{"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":2,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.busted.dk\/blog\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}