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
Result = "First folder in root visited. Go to the previous drive?"
if(messagebox("yesno warning", Result, Path ++ " root") == 7)
quit
win.sendmessage(hwnd, 0x400+51, 2052, 0)
win.sendmessage(hwnd, 0x400+51, 2001, 0)
quit
endif
Result = Up(Path, Name)
if(Result == ".")
quit
if(not Result) do
tc.cd(hwnd, Path)
keys {home}
quit
endif
Path = Result
Result = Lowest(Path)
tc.cd(hwnd, Result)
quit
Function Up(Path, Name)
local FullPath = Path ++ Slash ++ ifelse(Name, Name ++ 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, "TreeUpX Script")
quit(".")
endif
local Temp = file.readall(Report)
local v = vec.createfromlines(Temp)
if(v <= 0) do
messagebox("ok error", "Vector not created", "VEC plugin error")
quit(".")
endif
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 /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(".")
endif
if(file.size(Report) + 1 == length(Path))
quit
local Temp = file.readall(Report)
local v = vec.createfromlines(Temp)
if(v <= 0) do
messagebox("ok error", "Vector not created", "VEC plugin error")
quit(".")
endif
v.sortstring
Temp = v.length
quit(v[Temp - 1])
Function PutQuote(Str)
if(find(Str, " ") != -1) do
Str = trim(Str, Quote, 3)
Str = Quote ++ Str ++ Quote
endif
quit(Str)