|
Title | Join Subdirectories |
File Name | JoinSubDirs.txt |
Description | Copy (and rename) files from child directories to parent one |
Author | Vochomurka |
Parameters |
("%L", "%P") or ("%L", "%P", "string") |
Plugins Called | file, osd |
Icon | |
Version | 1.1 |
Updated on | 16.06.2014 |
local fh = file.open(arg(1), "r") local Str, Dir, Par local Qu = esc(?+\"+, ?+\+) osd.show("Wait...", "INFINITE", "48", "Arial Cyr", "-1", "255 000 000") if(fh > 0) do for(not(file.eof(fh))) Str = file.readstring(fh) if(Str) do if(arg(0) == 3) do ;Sub_ParsePath - name of script ParsePath; Dir = arg(2) ++ runfile.Subs\Sub_ParsePath(Str, 1) ++ arg(3) ;Sub_MoveFile - name of script MoveFile; Par = "runfile.Subs\Sub_MoveFile(" ++ Qu ++ "|" ++ Qu ++ ", Dir)" file.allfiles(Str, Par) else Par = Str ++ "*.*" if(file.move(Par, arg(2), 1) != "1") do file.close(fh) quit endif endif file.delete(remove(Str, -1)) endif endfor else messagebox("ok error", "File not opened", "FILE plugin error") osd.hide quit endif file.close(fh) win.sendmessage(win.handle("c=TTOTAL_CMD"), 0x400+51, 540, 0) osd.show("Ready!", "1000", "48", "Arial Cyr", "-1", "000 255 000") osd.hide
Suppose there is the following directory structure:
Folder1
File1.ext
File2.ext
Folder2
File3.ext
File4.ext
Two first script parameters are always ("%L", "%P"). If the third parameter is not specified, the script first moves files from child directories to the parent one, and then deletes child empty directories. In other words, selecting Folder1 and Folder2 and running script with parameters ("%L", "%P") leads to:
File1.ext
File2.ext
File3.ext
File4.ext
If, for example, there are same-name files in child directories, the third parameter can be specified. Then the resulting file name would be composed of three parts:
forler_name + 3rd_par + file_name
The + character means concatenation. For example, if script parameters are ("%L", "%P", ""), the file names would be:
Folder1File1.ext
Folder1File2.ext
Folder2File3.ext
Folder2File4.ext
For parameters ("%L", "%P", "'s child "):
Folder1's child File1.ext
Folder1's child File2.ext
Folder2's child File3.ext
Folder2's child File4.ext
The same result can be achieved with 1) setting [P][N] in the MultiRename Tool, 2) switching to branch view, 3) moving files, 4) deleting child directiries. The script is more quick, safe, and convenient though less flexible.
All Scripts | Total Commander | TotalCmd.net | PowerPro |