Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Скрипт меняющий имена двух объектов местами

 
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander printer-friendly view
View previous topic :: View next topic  
Author Message
helb



Joined: 08 Oct 2014
Posts: 57

Post (Separately) Posted: Thu Oct 16, 2014 13:48    Post subject: Скрипт меняющий имена двух объектов местами Reply with quote

Часто возникает необходимость поменять местами имена пары файлов/папок. Автоматизировал, сведя до одного нажатия на клавиатуре (у меня Ctrl+Shift+F11). Переименовывает либо ровно два выделенных объекта в текущей панели, либо то что под курсором в обеих.
Параметры: <имя1> <имя2> /<альтернативное имя>
Параметры в TC: %P%S /%T%M %L (последний опционален, для обновления списка в TC)
Code:
'==========================================================
' Swap names (by helb)
' Swaps two filenames, if only <file1> specified (in case of generated list) uses alternative
' Parameters: <file1> <file2> [/<alternative filename>]
' Total Commander parameters: %P%S /%T%M [%L] (two selected in current panel or under cursor in both panels, %L to refresh)
'Переименовывает либо ровно два выделенных объекта в текущей панели, либо то что под курсором в обеих.
'Параметры: <имя1> <имя2> /<альтернативное имя>
'Параметры в TC: %P%S /%T%M %L (последний опционален, для обновления списка в TC)
'==========================================================
unq1 = "swap1-e78d4204-b110-42b6-882e-c93cbab51cd7"
unq2 = "swap2-f8ea00d3-9b76-4039-89c6-8feab352c079"

with WScript.Arguments
   if .length < 2 then
      WScript.Echo("Insufficient parameters")
      WScript.Quit
   end if
   orig1 = .Item(0)
   if .length >= 3 and Left(.Item(1), 1) <> "/" and Left(.Item(2), 1) <> "/" or Left(.Item(0), 1) = "/" then
      WScript.Echo("More than two files specified")
      WScript.Quit
   else
      orig2 = .Item(1)
   end if
end with

set FSO = CreateObject("Scripting.FileSystemObject")

if Left(orig2, 1) = "/" then orig2 = Right(orig2, Len(orig2)-1)
if objExists(orig1) = 0 or objExists(orig2) = 0 then
   WScript.Echo("File not found")
   WScript.Quit
end if

set f1 = getObj(orig1)
set f2 = getObj(orig2)
orig1 = f1.Name
orig2 = f2.Name

if not renameObj(f1, unq1) then WScript.Quit
if not renameObj(f2, unq2) then
   f1.Name = orig1
   WScript.Quit
end if

f1.Name = orig2
f2.Name = orig1


function renameObj(f, newname)
   renameObj = true
   on error resume next
   f.Name = newname
   if err.Number <> 0 then
      WScript.Echo("Unable to rename: " & f.Name & vbNewLine & "Error #" & CStr(err.Number) & " " & err.Description)
      renameObj = false
      err.clear
   end if
end function

function getObj(fl)
   if FSO.FileExists(fl) then
      set getObj = FSO.GetFile(fl)
   elseif FSO.FolderExists(fl) then
      set getObj = FSO.GetFolder(fl)
   else
      set getObj = nothing
   end if
end function

'0=not exists, 1=is file, 2=is folder
function objExists(name)
   if FSO.FileExists(name) then
      objExists = 1
   elseif FSO.FolderExists(name) then
      objExists = 2
   else
      objExists = 0
   end if
end function
Back to top
View user's profile Send private message
HA3APET



Joined: 22 Feb 2010
Posts: 151

Post (Separately) Posted: Thu Feb 19, 2015 04:23    Post subject: Reply with quote

helb
Если в пути к скрипту есть пробел, то он не работает.
Поправьте пожалуйста.
Back to top
View user's profile Send private message
sa



Joined: 29 Apr 2009
Posts: 2567

Post (Separately) Posted: Thu Feb 19, 2015 11:18    Post subject: Reply with quote

HA3APET wrote:
не работает.

По-моему, вопрос к тоталу: что-то связанное с неверной обработкой параметра %S при наличии пробела в пути/имени программы.
В чём-то перекликается с
Quote:
03.06.11 Исправлено: Панель инструментов: Вместо запуска программы в "c:\Program Files" с параметром %S мог запуститься (если существовал) файл c:\Program.exe. (32/64)
Back to top
View user's profile Send private message
helb



Joined: 08 Oct 2014
Posts: 57

Post (Separately) Posted: Thu Feb 19, 2015 14:00    Post subject: Reply with quote

Да, это к Тоталу. Попробуйте команду (полный путь скрипта в кавычках и параметры) напрямую в cmd запустить — работает нормально. Так что держите скрипты в специально отведенном месте без пробелов в пути.
Back to top
View user's profile Send private message
HA3APET



Joined: 22 Feb 2010
Posts: 151

Post (Separately) Posted: Thu Feb 19, 2015 15:49    Post subject: Reply with quote

Кавычки в параметрах не помогают, ч то с ними что без них результат один.
Например, если путь такой c:\totalcmd 63\Scripts\Swap.vbs
Code:
TOTALCMD#BAR#DATA
"%COMMANDER_PATH%\Scripts\Swap.vbs"
"%P%S" /%T%M %L
C:\Windows\System32\WScript.exe,3
Поменять местами имена двух файлов/папок под курсором


-1

То ошибка такая:


То есть спотыкается на пробеле.
Back to top
View user's profile Send private message
helb



Joined: 08 Oct 2014
Posts: 57

Post (Separately) Posted: Thu Feb 19, 2015 16:40    Post subject: Reply with quote

Об этом и речь, кавычки в самом Тотале не спасают. Они всё равно где-то теряются, и он пытается это безобразие выполнить.

Попробовал вариант напрямую скрипт-хост указывать — работает.
Команда: wscript.exe "<полный путь скрипта>"
Back to top
View user's profile Send private message
HA3APET



Joined: 22 Feb 2010
Posts: 151

Post (Separately) Posted: Thu Feb 19, 2015 22:58    Post subject: Reply with quote

helb
Во, супер, так заработало. Спасибо за скрипт.
TOTALCMD#BAR#DATA
wscript.exe "%COMMANDER_PATH%\Scripts\Swap.vbs"
%P%S /%T%M %L
C:\Windows\System32\WScript.exe,3
Поменять местами имена двух файлов/папок под курсором


-1
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group