Is there or could there be support opening relative path shortcuts?

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

The parameter format of the relative path shortcut is "Target Args", e.g. "C:\Windows\explorer.exe ..\..\aaa\bbb\"
or "C:\Windows\explorer.exe ..\..\aaa\bbb\11.txt"

Can totalcmd support opening relative path shortcuts?
If it is a relative path shortcut to a file, it will be treated like a file by internal associations as a priority.
If it is a relative path shortcut to a directory, it will be treated like a directory and opened in the current panel via totolcmd.





That started over there >> https://ghisler.ch/board/viewtopic.php?t=78413
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Is there or could there be support opening relative path shortcuts?

Post by *ghisler(Author) »

Do you mean .lnk files containing relative paths? So far I couldn't create these, how did you achieve that?
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 4594
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Is there or could there be support opening relative path shortcuts?

Post by *white »

2ghisler(Author)
The wording "relative path shortcuts" is confusing. They are not relative path shortcuts, but normal shortcuts to explorer with a parameter containing a relative path.

See here (replace http with https in the link to the Relative tool ).
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *Fla$her »

ghisler(Author) wrote: 2023-02-09, 11:21 UTCSo far I couldn't create these, how did you achieve that?
There is nothing complicated here. Example with execution .vbs from TC:

Code: Select all

With CreateObject("WScript.Shell")
   NF = .Environment("PROCESS")("COMMANDER_PATH") & "\Sub1\Sub2"
   CreateObject("Shell.Application").NameSpace(Left(NF, 2)).NewFolder Mid(NF, 4)
   With .CreateShortcut(NF & "\TOTALCMD.CHM.lnk")
     .TargetPath = "%WINDIR%\explorer.exe"
     .Arguments = "..\..\TOTALCMD.CHM"
     .IconLocation = "%WINDIR%\hh.exe"
     .Save
   End With
   .Exec "%COMMANDER_EXE% /A /S /O0 """ & NF & "\TOTALCMD.CHM.lnk"""
End With
There's just one catch. There won't necessarily be explorer.exe, there may be other combinations. For example:

Code: Select all

%WinDir%\System32\rundll32.exe url.dll, OpenURL
%WinDir%\System32\rundll32.exe url.dll, FileProtocolHandler
%WinDir%\System32\rundll32.exe shell32.dll,ShellExec_RunDLL
Overquoting is evil! 👎
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

Fla$her wrote: 2023-02-09, 13:14 UTC
ghisler(Author) wrote: 2023-02-09, 11:21 UTCSo far I couldn't create these, how did you achieve that?
There is nothing complicated here. Example with execution .vbs from TC:

Code: Select all

With CreateObject("WScript.Shell")
   NF = .Environment("PROCESS")("COMMANDER_PATH") & "\Sub1\Sub2"
   CreateObject("Shell.Application").NameSpace(Left(NF, 2)).NewFolder Mid(NF, 4)
   With .CreateShortcut(NF & "\TOTALCMD.CHM.lnk")
     .TargetPath = "%WINDIR%\explorer.exe"
     .Arguments = "..\..\TOTALCMD.CHM"
     .IconLocation = "%WINDIR%\hh.exe"
     .Save
   End With
   .Exec "%COMMANDER_EXE% /A /S /O0 """ & NF & "\TOTALCMD.CHM.lnk"""
End With
There's just one catch. There won't necessarily be explorer.exe, there may be other combinations. For example:

Code: Select all

%WinDir%\System32\rundll32.exe url.dll, OpenURL
%WinDir%\System32\rundll32.exe url.dll, FileProtocolHandler
%WinDir%\System32\rundll32.exe shell32.dll,ShellExec_RunDLL
Thank you for your explanation, I created it using ahk.
FileCreateShortcut, %SystemRoot%\explorer.exe, LinkName.lnk,,%relativePath% , ,imageres.dll ,, 279
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

white wrote: 2023-02-09, 12:15 UTC 2ghisler(Author)
The wording "relative path shortcuts" is confusing. They are not relative path shortcuts, but normal shortcuts to explorer with a parameter containing a relative path.

See here (replace http with https in the link to the Relative tool ).
It is possible that the name is wrong. In the Chinese environment, we all call it this way.
But I saw Microsoft's official reply is also called so.
https://answers.microsoft.com/en-us/windows/forum/all/how-to-create-a-shortcut-with-relative-path/3e1b0ede-1e18-4ecd-937b-66756d3409d3
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Is there or could there be support opening relative path shortcuts?

Post by *ghisler(Author) »

I have tried your vbscript - links to files already work, but links to folders open an Explorer window instead of being opened internally. If you want me to support these links, you need to provide a way to detect them.

So far you have provided the following list:

Code: Select all

%WINDIR%\explorer.exe"
%WinDir%\System32\rundll32.exe url.dll, OpenURL
%WinDir%\System32\rundll32.exe url.dll, FileProtocolHandler
%WinDir%\System32\rundll32.exe shell32.dll,ShellExec_RunDLL
Of course it would also have to check without environment variables, so better expand them before comparing. a varying amount of spaces may also further complicate it. Any other things to consider?
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 4594
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Is there or could there be support opening relative path shortcuts?

Post by *white »

That a support employee uses this terminology doesn't mean it is an official statement by Microsoft.
ghisler(Author) wrote: 2023-02-13, 11:07 UTC Of course it would also have to check without environment variables, so better expand them before comparing. a varying amount of spaces may also further complicate it. Any other things to consider?
I believe there is also a variant with cmd:
%comspec% /c start <relative path to file or folder>

Furthermore, shouldn't it be optional? People may have created these shortcuts to launch Explorer from Total Commander..
Fla$her
Power Member
Power Member
Posts: 2244
Joined: 2020-01-18, 04:03 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *Fla$her »

ghisler(Author) wrote: 2023-02-13, 11:07 UTCbut links to folders open an Explorer window instead of being opened internally.
This is the essence of the request, so that the opening takes place in the TC file panel.
I also did a test version for the folder, if someone suddenly needs it.

Code: Select all

With CreateObject("WScript.Shell")
   NF = .Environment("PROCESS")("COMMANDER_PATH") & "\Sub1\Sub2\"
   CreateObject("Shell.Application").NameSpace(Left(NF, 2)).NewFolder Mid(NF, 4)
   With .CreateShortcut(NF & "Language.lnk")
     .TargetPath = "%WinDir%\System32\rundll32.exe"
     .Arguments = "url.dll, OpenURL ..\..\Language\"
     .IconLocation = "shell32.dll,2"
     .Save
   End With
   .Exec "%COMMANDER_EXE% /P /S /O0 """ & NF & "Language.lnk"""
End With
With regard to files, you can think about internal associations, if possible.
ghisler(Author) wrote: 2023-02-13, 11:07 UTCa varying amount of spaces may also further complicate it.
It is better to solve this by using regular expressions. For example: ^%ComSpec% *(/q *)?/c *start *("")? *(..?\)*([^*|<>?:"]+)$
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Is there or could there be support opening relative path shortcuts?

Post by *ghisler(Author) »

Furthermore, shouldn't it be optional? People may have created these shortcuts to launch Explorer from Total Commander..
This is a valid request. Maybe I should only support some of the variants?
Author of Total Commander
https://www.ghisler.com
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

ghisler(Author) wrote: 2023-02-13, 11:07 UTC I have tried your vbscript - links to files already work, but links to folders open an Explorer window instead of being opened internally. If you want me to support these links, you need to provide a way to detect them.

So far you have provided the following list:

Code: Select all

%WINDIR%\explorer.exe"
%WinDir%\System32\rundll32.exe url.dll, OpenURL
%WinDir%\System32\rundll32.exe url.dll, FileProtocolHandler
%WinDir%\System32\rundll32.exe shell32.dll,ShellExec_RunDLL
Of course it would also have to check without environment variables, so better expand them before comparing. a varying amount of spaces may also further complicate it. Any other things to consider?
Previous versions of TCIMG have the function of creating relative link shortcuts, but only support directly related directories, such as "D:\01\011\0111" and "D:\01\011\0111\01111\" relative paths
But "D:\01\011\0111" and "D:\01\021\0222" are not supported.
After I submitted the bug, the author made a fix
TCIMG also supports directory shortcuts to be opened with the current tab in TC, but relative paths are not supported.

The functionality I expect is:
1. When opening a file, use TC internal association
2. When opening the directory, use the tab opposite the TC, or provide parameters to configure local or opposite. The reason is that after pressing Backspace, instead of returning to the original directory, it returns to the upper level of the directory where the shortcut is located, so it is best to open it on the opposite side.

The following vbs command can create a relative path shortcut:

Code: Select all

Function GetRelativePathA(sPath, sFolder)
  GetRelativePathA = sPath
  If sPath = sFolder Then Exit Function
  If Right(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
  If sPath = sFolder Then Exit Function
  aPath = Split(sPath, "\") : aFolder = Split(sFolder, "\")
  If aPath(0) <> aFolder(0) Then Exit Function 
  nP = UBound(aPath) : nF = UBound(aFolder)

  For i = 0 To nP
    If i > nF Or aPath(i) <> aFolder(i) Then Exit For
  Next
  For j = i To nF - 1
    relativePath = relativePath & "..\"
  Next
  For j = i To nP- 1
    relativePath = relativePath & aPath(j) & "\"
  Next
  GetRelativePathA = relativePath & aPath(nP)
End Function
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

Currently I'm using ahk to achieve:
According to the path where the shortcut file is located, after converting the parameters of the shortcut into an absolute path, determine its properties
1. If it is a file, open it with F4Menu
2. If it is a directory, use the tab opposite to TC to open it
Last edited by yahuu on 2023-02-22, 04:13 UTC, edited 1 time in total.
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

white wrote: 2023-02-13, 11:28 UTC
That a support employee uses this terminology doesn't mean it is an official statement by Microsoft.
ghisler(Author) wrote: 2023-02-13, 11:07 UTC Of course it would also have to check without environment variables, so better expand them before comparing. a varying amount of spaces may also further complicate it. Any other things to consider?
I believe there is also a variant with cmd:
%comspec% /c start <relative path to file or folder>

Furthermore, shouldn't it be optional? People may have created these shortcuts to launch Explorer from Total Commander..
%comspec% works, but I tried using totalcmd.exe with command line arguments and it still doesn't work. It should be that totalcmd.exe does not know the relative path relative to whom.
User avatar
yahuu
Junior Member
Junior Member
Posts: 57
Joined: 2015-01-15, 03:19 UTC

Re: Is there or could there be support opening relative path shortcuts?

Post by *yahuu »

Thanks ghisler
If the original object of the relative path shortcut is a folder, TC11B2 already supports opening it.

However, if the original object of the relative path shortcut is a file, it will still open with the default association of the OS. Is it possible to open it with TC's internal association? Not the internal association of the lnk file, but the internal association of the original file type.
For example
a.txt shortcut x.lnk , should be opened with the internal association of the txt format.
b.pdf shortcut y.lnk , should be opened with the internal association of the pdf format.

First, according to the Target Args parameters and lnk is located in the directory, the relative path to restore the absolute path, and then open the file according to the TC internal association.


Also, is it possible to add a parameter to open a shortcut to a folder in the opposite window? Because when Backspace is pressed, it returns to the previous level of the original folder, not the folder where lnk is located.
Post Reply