ToRoot

Title ToRoot
File Name ToRoot.txt
Description Decrease depth level of current directory
Author Vochomurka
Parameters ("%P")
Plugins Called file, win, tc
Icon
Version 1.0
Updated on 27.01.2006
External Utility Xxcopy
local Path = file.folder(arg(1))
Path = file.folder(Path)
local hwnd = win.handle("c=TTOTAL_CMD")
local List, Count, Dest, Folder 

for(1)
	List = file.listfiles(Path, "2")
	Count = line(List, 0)
	if(Count < 2) do
		Folder = ifelse(Dest == "", remove(arg(1), -1), Dest)
		Dest = Path
		Path = file.folder(Path)
	else
		break
	endif
endfor

if(Dest == "")
	quit

Path = arg(1) ++ "*.* " ++ Dest ++ " /s /rc /yy"
file.runwait(0, "path\xxcopy.exe", Path, "", "hide")
tc.cd(hwnd, Dest)
wait 1
file.delete(Folder)
win.postmessage(hwnd, 0x400+51, 540, 0)

Comments:

Suppose there is the following directory structure:

Folder1
Folder2
	Folder3
		Folder4
			Folder5
				Folder6
				File1
				File2
File3

So, there are some nesting directories containing each of them only one subdirectory. In our example these nesting directories are Folder2-Folder3-Folder4. Script moves all files and folders from the current directory (underlined) to Folder3, to preserve the minimum nesting required, and then removes empty directories. The result would be:

Folder1
Folder2
	Folder3
		Folder6
		File1
		File2
File3

In other words, if in the full path (Folder2\Folder3\Folder4\Folder5 in our case) there are directories containing only one subdirectories, all of them (but two first ones) would be deleted and the full path would be Folder2\Folder3. It could be also said that the script eliminates the redundant nesting.


Main Page Total Commander PowerPro