TreeUpX

Title TreeUpX
File Name TreeUpX.txt
Description Move up the directory tree
Author Vochomurka (idea by Gregory)
Parameters %P%N
Plugins Called win, file, tc, miscplugin, vec
Icon
Version 3.0
Updated on 13.03.2010
External Utility Xxcopy
local FullPath = x9
local hwnd = win.handle("c=TTOTAL_CMD")
static Quote = esc(?+\"+, ?+\+)
static Slash = "\"
static XX = "path\xxcopy.exe"
local Path = file.folder(FullPath)
Path = trim(Path, " ", 3)
Path = trim(Path, Quote, 3)
local Name = file.nametype(FullPath)
Name = trim(Name, Quote, 3)

local Result

if(select(Path, 2) == "\\") do
	Result = "Script works only in directory tree, not network or special folders"
	messagebox("ok error", Result, "TreeUpX Script")
	quit
endif

if(length(Path) > 3) do
	Name = file.nametype(Path)
	Path = file.folder(Path)
else
	*Exec Prompt 1 First folder in root visited. Go to the previous drive?
	if(not pproflag(1))
		quit

	win.sendmessage(hwnd, 0x400+51, 2052, 0)		
	win.sendmessage(hwnd, 0x400+51, 2001, 0)		
	quit
endif

Result = Up(Path, Name)
if(Result == -1)					
	quit

if(not Result) do					
	win.sendmessage(hwnd, 0x400+51, 2002, 0)		
	keys {home}
	quit
endif

Path = Result
Result = Lowest(Path)
tc.cd(hwnd, Result)
keys {home}
quit
//=============================================
Function Up(Path, Name)

local FullPath = Path ++ ifelse(Name != "", Slash ++ Name ++ Slash, Slash)
Path = PutQuote(Path ++ "\*.*")
FullPath = trim(FullPath, Quote, 3)

local Report = miscplugin.tempfilename()
local Str = Path ++ " /ltree /dl2 /h /fo" ++ Report

local ExitCode = file.runwait(0, XX, Str, "", "hide")
if(ExitCode != 0 && ExitCode != 100) do
	messagebox("ok error", "XXcopy error #" ++ ExitCode, "TreeUpXMouse Script")
	quit(-1)
endif

local Temp = file.readall(Report)
Report = line(Temp, 0)

local v = vec.create(Report)
if(v <= 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error")
	quit(-1)
endif

for(i = 0; i < Report; i++)
	Str = trim(line(Temp, i + 1), "<DIR>", 2)
	v[i] = trim(Str, " ", 2)
endfor

v.sortstring
Temp = v.binsearch(FullPath)

if(Temp == 1) do
	quit
else
	quit(v[Temp - 1])
endif

//=============================================
Function Lowest(Path)

local Param = PutQuote(Path ++ "*.*")
local Report = miscplugin.tempfilename()
local Str = Param ++ " /ltree /h /e /fo" ++ Report

local ExitCode = file.runwait(0, XX, Str, "", "hide")

if(ExitCode != 0 && ExitCode != 100) do
	messagebox("ok error", "XXcopy error #" ++ ExitCode, "TreeUpX Script")
	quit all
endif

local Temp = file.readall(Report)
Report = line(Temp, 0)

if(Report == 1)
	quit(Path)

Str = trim(line(Temp, Report), "<DIR>", 2)
Str = trim(Str, " ", 2)
quit(Str)
//=============================================
Function PutQuote(Str)
if(find(Str, " ") != -1) do
	Str = trim(Str, Quote, 3)
	Str = Quote ++ 	Str ++ Quote
endif
quit(Str)

Comments:

See Tree Movement description


Main Page Total Commander PowerPro