{"id":151,"date":"2021-09-03T01:59:33","date_gmt":"2021-09-03T01:59:33","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/batch-file-to-rename-files-by-date"},"modified":"2021-09-03T03:10:40","modified_gmt":"2021-09-03T03:10:40","slug":"batch-file-to-rename-files-by-date","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/dos\/batch-file-to-rename-files-by-date\/5517.html","title":{"rendered":"batch file to rename files by date."},"content":{"rendered":"<p>Help! I&#8217;m have been trying to figure a way to write a batch file that will automatically rename a specific file by the date and time.<\/p>\n<p>example: skidog.txt ==&gt; jan191230.txt<\/p>\n<p>Hmmm.<br \/>\nThe below will rename a file in dirtest<br \/>\nto todays date. Just change the path.<\/p>\n<p>CLS<br \/>\n@ECHO OFF<br \/>\nIF NOT &#8220;%1&#8243;==&#8221;date&#8221; ECHO Program will rename ECHO a filewith todays date.<br \/>\nIF &#8220;%3&#8243;==&#8221;Mon&#8221; SET Day=Monday<br \/>\nIF &#8220;%3&#8243;==&#8221;Tue&#8221; SET Day=Tuesday<br \/>\nIF &#8220;%3&#8243;==&#8221;Wed&#8221; SET Day=Wednesday<br \/>\nIF &#8220;%3&#8243;==&#8221;Thu&#8221; SET Day=Thursday<br \/>\nIF &#8220;%3&#8243;==&#8221;Fri&#8221; SET Day=Friday<br \/>\nIF &#8220;%3&#8243;==&#8221;Sat&#8221; SET Day=Saturday<br \/>\nIF &#8220;%3&#8243;==&#8221;Sun&#8221; SET Day=Sunday<br \/>\nSet FullDate=%4<br \/>\ngoto getdate<br \/>\n:start2<br \/>\necho rename test*.* %fulldate%.* &gt; try.bat<br \/>\ncall try<br \/>\nrem del try.bat<br \/>\ngoto end<br \/>\n:getdate<br \/>\nECHO.|DATE&gt;t.bat<br \/>\nCALL t.bat<br \/>\nDEL t.bat<br \/>\ngoto start2<br \/>\n:end<br \/>\necho A file called %fulldate% has been ECHO created.<\/p>\n<p>Easiest approach:<\/p>\n<p>Requires the ability to use the DOS extensions (NT4 SP3 or SP4 onwards I think???)<\/p>\n<p>rem Rename File<\/p>\n<p>@echo off<\/p>\n<p>rem Enable Extensions<br \/>\nverify other 2&gt;nul<br \/>\nsetlocal enableextensions<br \/>\nif errorlevel 1 goto ErrNoExtensions<\/p>\n<p>rem Set current Date &amp; Time variables. Change the following lines to get the correct info out. For more info, use the DOS command: help set<br \/>\nset SHORTDATE=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%<br \/>\nset SHORTTIME=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%<\/p>\n<p>rem Rename file<br \/>\nren %1 %SHORTDATE%_%SHORTTIME%.*<\/p>\n<p>endlocal<\/p>\n<p>goto end<\/p>\n<p>:ErrNoExtensions<br \/>\necho Extensions not enabled. Cannot continue.<\/p>\n<p>:End<\/p>\n<p>I am looking to make a similar script, but mine needs to capture the output of a small dos application i have created and rename the file to that output.<br \/>\nc:<a style=\"cursor: help; text-decoration: underline; color: #000000;\">test.exe<\/a> file.txt<br \/>\nOUTPUT<\/p>\n<p>I want file.txt to be renamed to OUTPUT, but i cant figure out how. Thanks in advance.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"inline_featured_image":false,"iawp_total_views":18},"question-category":[60],"question_tags":[],"class_list":["post-151","question","type-question","status-publish","hentry","question-category-dos"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=151"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=151"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}