TreeUp

Title TreeUp
File Name TreeUp.txt
Description Move up the directory tree
Author Vochomurka (idea by Gregory)
Parameters "%p", "%n"
Plugins Called win, file, tc
Icon
Version 1.0
Updated on 23.10.2005

local hwnd = win.handle("c=TTOTAL_CMD")
local Path = arg(1)
local Name = arg(2)
local List, Counter, Slash, j, One

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

Path = remove(Path, -1)
Slash = revindex(Path, "\")
Name = select(Path, Slash - length(Path))
Path = select(Path, Slash - 1)

for(1)
	List = file.listfiles(Path, 2, 0, 1)
	Counter = line(List, 0)
	Slash = " "
	flag clear 1

	if(Counter == 1) do
		tc.cd(hwnd, Path)
		keys {home}
		quit
	endif

	for(j = 1; j <= Counter; j = j + 1)
		One = file.getShortPath(line(List, j))
		if(file.isfolder(One) == "1" && max(One, Path ++ "\" ++ Name) != One) do
			flag set 1
			Slash = max(One, Slash)
		endif
	endfor

	if(pproflag(1)) do
		Path = Slash
		break
	else
		if(length(Path) == 2) do
			Path = select(Path, 2)
			Slash = "First folder in root visited. Go to the previous drive?"
			if(messagebox("yesno warning", Slash, Path ++ " root") == 7)
				quit

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

		Slash = revindex(Path, "\")
		Name = select(Path, Slash - length(Path))
		Path = select(Path, Slash - 1)
	endif
endfor								

for(1)
	List = file.listfiles(Path, 2, 0, 1)
	Counter = line(List, 0)

	if(Counter == 0) do										
		tc.cd(hwnd, Path)
		keys {home}
		quit
	else
		Slash = " "
		flag clear 1

		for(j = 1; j <= Counter; j = j + 1)
			One = file.getShortPath(line(List, j))
			if(file.isfolder(One) == "1") do
				flag set 1
				Slash = max(One, Slash)
			endif
		endfor

		if(pproflag(1)) do
			Path = Slash
		else
			tc.cd(hwnd, Path)
			keys {home}
			quit
		endif
	endif
endfor							

Comments:

See comments to the TreeDown script.


Main Page Total Commander PowerPro