Update last modified time of shortcut when orig file is modf

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Update last modified time of shortcut when orig file is modf

#1 Post by pstein » 26 Jul 2014 00:51

Assume I have (under Win 7) a (log)file and (in another directory) a shortcut which points to this file.

Each original file and its shortcut have their own last modified timestamp (as shown in WinExplorer column).

Unfortunately when the original file is modified the timestamp of the depending shortcut file IS NOT modified too.

Is there a way to let the shortcut be touched as well?

There is no need of an immediate update of the last modified timestamp of the shortcut object.

It am searching for a DOS batch script which runs later over the whole partition, searches for shortcuts, compares their timestamp with the timestamp of their target files and uses a touch.exe command to adjust the shortcuts last modified timestamp acccordingly.

The batch script should work for folder shortcuts as well.

How can I implement such a batch script?

Peter

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Update last modified time of shortcut when orig file is

#2 Post by foxidrive » 26 Jul 2014 02:26

You can check to see if a shortcut contains time related stamps of the target file/folder - TTBOMK they don't.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Update last modified time of shortcut when orig file is

#3 Post by aGerman » 28 Jul 2014 15:01

Your log and the shortcut are two different files. The time stamps of the shortcut are not updated because it was not changed.

It's not the answer to your question but you could read the target path out of the shortcut and determine its date last modified.

Save as batch file and drag/drop the shortcut onto it:

Code: Select all

@if (@X)==(@Y) @end /* line that initiates a JScript comment

:: Batch part:
@echo off &setlocal
cscript //e:jscript //nologo "%~f0" %*
pause
goto :eof


:: JScript part: */
try {
  WScript.StdOut.WriteLine(WScript.CreateObject("Scripting.FileSystemObject")
    .GetFile(WScript.CreateObject("WScript.Shell")
    .CreateShortcut(WScript.Arguments.Item(0)).TargetPath)
    .DateLastModified);
}
catch(e) {
  WScript.StdErr.WriteLine(e.description);
}

You could also execute the cscript line into a FOR /F loop to save the output in variables.

Code: Select all

for /f "tokens=1*" %%i in ('cscript //e:jscript //nologo "%~f0" %*') do (
  set "targetdate=%%i"
  set "targettime=%%j"
)

(the tokens may differ depending on your settings)

Regards
aGerman

Post Reply