AutoHotkey: Create shortcuts keeping timestamps: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
(Created page with "This script creates shortcuts in the target panel to files selected in the source panel while keeping the shortcuts' timestamps the same as those of the original files. Loop...")
 
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 12: Line 12:


  "%L" "%T\"
  "%L" "%T\"
Alternative version to also process files in selected subdirectories:
Loop, Read, %1%
{
    FileGetAttrib, Attrib, %A_LoopReadLine%
    IfInString, Attrib, D
    {
      RegExMatch(A_LoopReadLine, ".*\\\K.*?(?=\\)", TopDirName)
      StringLen, SourceAbsolutePathLength, A_LoopReadLine
      SourceAbsolutePathLength--
      Loop, Files, %A_LoopReadLine%*.*, R
      {
          SplitPath, A_LoopFileLongPath, FileNameWithExt, SourceSubDirPath, , FileName
          StringTrimLeft, TargetSubDirPath, SourceSubDirPath, SourceAbsolutePathLength
          FileGetTime, TimeStamp, %A_LoopFileLongPath%
          FileCreateDir, %2%%TopDirName%%TargetSubDirPath%
          FileCreateShortcut, %A_LoopFileLongPath%, %2%%TopDirName%%TargetSubDirPath%\%FileName%.lnk
          FileSetTime, %TimeStamp%, %2%%TopDirName%%TargetSubDirPath%\%FileName%.lnk
      }
      Continue
    }
    SplitPath, A_LoopReadLine, FileNameWithExt, , , FileName
    FileGetTime, TimeStamp, %A_LoopReadLine%
    FileCreateShortcut, %A_LoopReadLine%, %2%%FileName%.lnk
    FileSetTime, %TimeStamp%, %2%%FileName%.lnk
}
If you would like to include the file extension in the shortcut (filename.ext.lnk instead of filename.lnk), replace %FileName% with %FileNameWithExt% in all four FileSetTime and FileCreateShortcut lines.


Back to [[AutoHotkey]]
Back to [[AutoHotkey]]
[[Category:AutoHotkey scripts|Create shortcuts keeping timestamps]]

Latest revision as of 16:45, 13 June 2016

This script creates shortcuts in the target panel to files selected in the source panel while keeping the shortcuts' timestamps the same as those of the original files.

Loop, Read, %1%
{
	SplitPath, A_LoopReadLine, , , , FileName
	FileGetTime, TimeStamp, %A_LoopReadLine%
	FileCreateShortcut, %A_LoopReadLine%, %2%%FileName%.lnk
	FileSetTime, %TimeStamp%, %2%%FileName%.lnk
}

To use, adda button to the Button Bar (or create a menu entry or user command for an alias or a keyboard shortcut) with the following parameters:

"%L" "%T\"

Alternative version to also process files in selected subdirectories:

Loop, Read, %1%
{
   FileGetAttrib, Attrib, %A_LoopReadLine%
   IfInString, Attrib, D
   {
      RegExMatch(A_LoopReadLine, ".*\\\K.*?(?=\\)", TopDirName)
      StringLen, SourceAbsolutePathLength, A_LoopReadLine
      SourceAbsolutePathLength--
      Loop, Files, %A_LoopReadLine%*.*, R
      {
         SplitPath, A_LoopFileLongPath, FileNameWithExt, SourceSubDirPath, , FileName
         StringTrimLeft, TargetSubDirPath, SourceSubDirPath, SourceAbsolutePathLength
         FileGetTime, TimeStamp, %A_LoopFileLongPath%
         FileCreateDir, %2%%TopDirName%%TargetSubDirPath%
         FileCreateShortcut, %A_LoopFileLongPath%, %2%%TopDirName%%TargetSubDirPath%\%FileName%.lnk
         FileSetTime, %TimeStamp%, %2%%TopDirName%%TargetSubDirPath%\%FileName%.lnk
      }
      Continue
   }

   SplitPath, A_LoopReadLine, FileNameWithExt, , , FileName
   FileGetTime, TimeStamp, %A_LoopReadLine%
   FileCreateShortcut, %A_LoopReadLine%, %2%%FileName%.lnk
   FileSetTime, %TimeStamp%, %2%%FileName%.lnk 
}

If you would like to include the file extension in the shortcut (filename.ext.lnk instead of filename.lnk), replace %FileName% with %FileNameWithExt% in all four FileSetTime and FileCreateShortcut lines.

Back to AutoHotkey