{"id":1497,"date":"2016-02-26T19:57:54","date_gmt":"2016-02-26T17:57:54","guid":{"rendered":"http:\/\/www.kavdesign.net\/blog\/?p=1497"},"modified":"2016-05-17T10:40:23","modified_gmt":"2016-05-17T08:40:23","slug":"how-to-remove-text-from-file-name-for-multiple-files-on-windows","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/other\/how-to-remove-text-from-file-name-for-multiple-files-on-windows\/","title":{"rendered":"How to remove text from file name for multiple files on Windows"},"content":{"rendered":"<div class=\"post-text\">\n<p>On Windows, you can take advantage of PowerShell:<\/p>\n<pre class=\"default prettyprint prettyprinted\"><code><span class=\"pln\">dir <\/span><span class=\"pun\">|<\/span><span class=\"pln\"> rename<\/span><span class=\"pun\">-<\/span><span class=\"pln\">item <\/span><span class=\"pun\">\u2013<\/span><span class=\"pln\">newname <\/span><span class=\"pun\">{<\/span><span class=\"pln\"> $_<\/span><span class=\"pun\">.<\/span><span class=\"pln\">name <\/span><span class=\"pun\">\u2013<\/span><span class=\"pln\">ireplace <\/span><span class=\"str\">'(.+?) 203\\.bmp$'<\/span><span class=\"pun\">,<\/span><span class=\"str\">'$1.bmp'<\/span> <span class=\"pun\">}<\/span><\/code><\/pre>\n<p>In this code snippet we use a command that removes &#8216;203&#8217; from the file name.<\/p>\n<h3>Description<\/h3>\n<pre class=\"default prettyprint prettyprinted\"><code><span class=\"pln\">dir          <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> list the content of the current directory\r\n <\/span><span class=\"pun\">|<\/span>           <span class=\"pun\">=&gt;<\/span><span class=\"pln\"> send each found element to the <\/span><span class=\"kwd\">next<\/span><span class=\"pln\"> command\r\nrename<\/span><span class=\"pun\">-<\/span><span class=\"pln\">item  <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> rename an element <\/span><span class=\"kwd\">in<\/span><span class=\"pln\"> a <\/span><span class=\"typ\">Windows<\/span> <span class=\"typ\">PowerShell<\/span><span class=\"pln\"> provider namespaceject\r\n<\/span><span class=\"pun\">\u2013<\/span><span class=\"pln\">newname     <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> specify the name of the renamed file\r\n<\/span><span class=\"pun\">{<\/span><span class=\"pln\">\r\n    $_               <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> points to an <\/span><span class=\"kwd\">object<\/span><span class=\"pln\"> representing the actual file\r\n   <\/span><span class=\"pun\">.<\/span><span class=\"pln\">name             <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> the name <\/span><span class=\"kwd\">property<\/span><span class=\"pln\"> of the automatic variable\r\n   <\/span><span class=\"pun\">-<\/span><span class=\"pln\">ireplace         <\/span><span class=\"pun\">=&gt;<\/span><span class=\"pln\"> perform a insensitive replace\r\n   <\/span><span class=\"str\">'(.+?) 203\\.bmp$'<\/span> <span class=\"pun\">=&gt;<\/span><span class=\"pln\"> here comes the regex <\/span><span class=\"kwd\">for<\/span><span class=\"pln\"> matching the desired files\r\n   <\/span><span class=\"str\">'$1.bmp'<\/span>          <span class=\"pun\">=&gt;<\/span><span class=\"pln\"> the replacement <\/span><span class=\"kwd\">string<\/span>\r\n<span class=\"pun\">}<\/span><\/code><\/pre>\n<p>You must run this command inside a power shell. Here is how to start it:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/QmsXn.png\" alt=\"how to launch powershell on Windows 7?\" \/><\/p>\n<p>Then <code>cd<\/code> into you dir from the Powershell window:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/SUB7c.png\" alt=\"Change to the directory containing the files to be renamed from powershell window\" \/><\/p>\n<p>More on http:\/\/stackoverflow.com\/questions\/21837836\/how-to-rename-multiple-files-at-once-by-removing-a-varying-part-in-the-file-name<\/p>\n<p>Also &#8211; http:\/\/superuser.com\/questions\/236820\/how-do-i-remove-the-same-part-of-a-file-name-for-many-files-in-windows-7\/871799<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>On Windows, you can take advantage of PowerShell: dir | rename-item \u2013newname { $_.name \u2013ireplace &#8216;(.+?) 203\\.bmp$&#8217;,&#8217;$1.bmp&#8217; } In this code snippet we use a&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.kavdesign.net\/blog\/other\/how-to-remove-text-from-file-name-for-multiple-files-on-windows\/\">Continue reading<span class=\"screen-reader-text\">How to remove text from file name for multiple files on Windows<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9,1],"tags":[420,421,208,422,419],"class_list":["post-1497","post","type-post","status-publish","format-standard","hentry","category-coding","category-other","tag-file","tag-power","tag-rename","tag-shell","tag-windows","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":5,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"predecessor-version":[{"id":1511,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions\/1511"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}