Total Commander Knowledge Base

Есть вопрос?

Поищите ответ в самой большой русскоязычной базе знаний по Total Commander!

Перейти к файлу с другим расширением

Иногда требуется быстро перейти к первому файлу в панели или группе файлов с определённым расширением.
Следующий скрипт решает эту задачу.
Стоит обратить внимание на использование вспомогательного модуля TCS_Helper и утилиты TCMC.

' Перенос курсора на файл с другим расширением
' с функцией возврата в начало

' Необходима регистрация Script Helper ActiveX for TC
' Путь запуска в кнопке/пользовательской команде очистить

' Параметр: %N%Z

' Автор - Flasher ©
'========================================================
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TCS = CreateObject("TCScript.Helper")
Set D = CreateObject("Scripting.Dictionary")
On Error Resume Next
P = WScript.Arguments(0)
If Err.Number > 0 Or FSO.FolderExists(P) Then
  TCS.SendCommand 2050
  Quit
End If
'=============  Укажите путь к TCMC.exe  ================
TCMC = "%COMMANDER_PATH%\Utils\TCMC\TCMC.exe"
'========================================================
TCS.LockTC True
TCS.SendCommand 3302
S = TCS.GetSrcSelectedFiles(0)
TCS.SendCommand 3304
C = Ubound(S)+1
ExtP = LCase(FSO.GetExtensionName(P))
For Each F in S
  n = n + 1
  D.Add F, n
  If D.Exists(P) Then
    ExtF = LCase(FSO.GetExtensionName(F))
    If D.Item(P) = C Then
      TCS.SendCommand 2050
      Quit
    ElseIf D.Item(F) > D.Item(P) And ExtF <> ExtP Then
      With CreateObject("WScript.Shell") .Exec(TCMC & " cds """ &_
      .CurrentDirectory & "\" & F & "\:"" """"") End With
      Quit
    End If
  End if
Next
If ExtF = ExtP Then
  TCS.SendCommand 2050
  Quit
End If

Sub Quit
  TCS.LockTC False
  Set FSO = Nothing
  Set TCS = Nothing
  WScript.Quit
End Sub

Следующий скрипт будет отрабатывать чуть помедленней, но, в отличии от предшественника, срабатывать в режимах Файлы без подкаталогов и Файлы на панель после поискового запроса.

' Назначение:	переход к следующему файлу с другим расширением
'		с функцией возврата в начало списка
' Требование:	регистрация Script Helper ActiveX for TC
' Параметр:	%N%Z
' =============================================================
On Error Resume Next
P = WScript.Arguments(0)
Set FSO = CreateObject("Scripting.FileSystemObject")
With CreateObject("TCScript.Helper")
  If WScript.Arguments.Count = 0 Or FSO.FolderExists(P) Then
    .SendCommand 2050
  Else
    .LockTC True
    .SendCommand 527
    .SendCommand 525
    .SendCommand 2053
    .SendCommand 524
    T = .GetTextFromClip
    .SendCommand 2017, True
    If LCase(FSO.GetExtensionName(.GetTextFromClip)) =_
    LCase(FSO.GetExtensionName(P)) Then .SendCommand 2050
    .LockTC False
    .SetTextToClip(T)
  End If
End With
Set FSO = Nothing
WScript.Quit

Flasher
02.10.2011