{"id":6,"date":"2008-02-14T12:42:48","date_gmt":"2008-02-14T17:42:48","guid":{"rendered":"http:\/\/blog.bitsofgenius.com\/?p=6"},"modified":"2010-12-05T02:44:50","modified_gmt":"2010-12-05T06:44:50","slug":"touching-a-files-last-modified-time-stamp","status":"publish","type":"post","link":"https:\/\/blog.bitsofgenius.com\/?p=6","title":{"rendered":"&#8220;Touching&#8221; a file&#8217;s last-modified time stamp"},"content":{"rendered":"<p>The Unix world has long had utilities like &#8220;touch&#8221;, and DOS\/Windows console applications exist for this: to bump the file&#8217;s last modified date\/time to the current system time. In Windows 95\/98, I used shdate which added a tab on a file or folder&#8217;s property which allowed changing the time stamp.  Unfortunately, I haven&#8217;t seen it work well with XP.<\/p>\n<p>So assuming that all you want to do is change the last-modified date to the current time, for one or more files, the following script will do it for you.  Just save it to a location and file name of your choice, then execute the script.  That will inject a context-menu item into the HKEY_CLASSES_ROOT\\* called &#8220;touch&#8221;.  Just select one or more files in Windows Explorer, and select &#8220;Touch&#8221; from the context menu.<\/p>\n<p>That&#8217;s it.  Enjoy.  ( touch.vbs )<\/p>\n<pre lang=\"vb\" line=\"1\" escaped=\"true\">\r\n' Touch.vbs -- Take 1 or more files, and changes the last modified date to the current time.\r\n' John J Schultz -- Public Domain.\r\n'\r\n' Parameters\r\n'   wscript \/\/NOLOGO \/\/B TouchFiles.vbs {file1} [{file3} [...]]\r\n'\r\n' ----------------------------\r\n\r\nOption Explicit\r\n\r\nDim aFiles, oShell, oFS, oFolder, oArgs, iCount, bValidParameters, sLine, dTimestamp\r\n\r\nset oShell = WScript.CreateObject(&quot;WScript.Shell&quot;)\r\nsLine = &quot;&quot;\r\non error resume next\r\nsLine = oShell.RegRead (&quot;HKCR\\*\\shell\\Touch\\&quot;)\r\non error goto 0\r\nIf sLine = &quot;&quot; Then\r\n\toShell.RegWrite &quot;HKCR\\*\\shell\\Touch\\&quot;, &quot;Touch&quot;, &quot;REG_SZ&quot;\r\n\toShell.RegWrite &quot;HKCR\\*\\shell\\Touch\\command\\&quot;, &quot;wscript.exe &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot; &quot;&quot;%1&quot;&quot;&quot;, &quot;REG_SZ&quot;\r\n\tMsgBox &quot;You can now touch any file from the context menu in Windows Explorer, by right-clicking on the file and selecting Touch&quot;, vbOKonly + vbInformation, &quot;Shell extension installed.&quot;\r\n\tSet oShell = Nothing\r\n\tWScript.Quit (0)\r\nEnd If\r\nSet oShell = Nothing\r\n\r\nSet oArgs = WScript.Arguments\r\nbValidParameters = (oArgs.Count &gt;= 1)\r\nIf bValidParameters Then\r\n\tFor iCount = 0 to oArgs.Count - 1\r\n\t\tIf iCount = 0 Then\r\n\t\t\tReDim aFiles (iCount)\r\n\t\tElse\r\n\t\t\tReDim Preserve aFiles (iCount)\r\n\t\tEnd If\r\n\t\taFiles (iCount) = oArgs(iCount)\r\n\tNext\r\nEnd If\r\nSet oArgs = Nothing\r\n\r\nIf Not bValidParameters Then\r\n\tWScript.Echo &quot;Invalid parameters&quot;\r\n\tWScript.Quit(0)\r\nEnd If\r\n\r\ndTimeStamp = Now()\r\nSet oFS = CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\nSet oShell = CreateObject(&quot;Shell.Application&quot;)\r\nFor iCount = 0 To UBound (aFiles, 1)\r\n\tIf Not oFS.FileExists (aFiles (iCount)) Then\r\n\t\tWScript.Echo &quot;Skipping missing file: &quot; &amp; aFiles (iCount)\r\n\tElse\r\n\t\tSet oFolder = oShell.NameSpace(oFS.GetParentFolderName (aFiles (iCount)))\r\n\t\toFolder.Items.Item(oFS.GetFileName (aFiles (iCount))).ModifyDate = dTimeStamp\r\n\t\tSet oFolder = Nothing\r\n\tEnd If\r\nNext ' File\r\nSet oShell = Nothing\r\nSet oFS = Nothing\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Unix world has long had utilities like &#8220;touch&#8221;, and DOS\/Windows console applications exist for this: to bump the file&#8217;s last modified date\/time to the current system time. In Windows 95\/98, I used shdate which added a tab on a file or folder&#8217;s property which allowed changing the time stamp. Unfortunately, I haven&#8217;t seen it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-vbscript-intended-for-wscript-which-interfaces-with-windows-explorer"],"_links":{"self":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":0,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitsofgenius.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}