SortComments

Title SortComments
File Name SortComments.txt
Description Sort descript.ion (or any file) alphabetically
Author Vochomurka
Parameters "%P" (to sort descript.ion comments)
or
"%P", "%O", "%E", "_suffix" (to sort any text file)
Plugins Called file, vec
Icon
Version 2.0
Updated on 22.09.2010
local Source, Target

if(arg(0) == 1) do
	Source = arg(1) ++ "descript.ion"
	Target = Source
else
	Source = arg(1) ++ arg(2) ++ "." ++ arg(3)
	Target = arg(1) ++ arg(2) ++ arg(4) ++ "." ++ arg(3)
endif

if(not validpath(Source)) do
	messagebox("ok error", "File " ++ Source ++ " is missing", "No source file")
	quit
endif

local Str = file.readall(Source)
local v = vec.createfromlines(Str)

if(v <= 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error")
	quit
endif

vec.sortstring(v)
Str = vec.makelines(v)
file.writeall(Target, Str)
vec.unload

Comments:

First parameter is "%P" (source panel) or "%T" (target panel). If there are no more parameters, then the lines of the descript.ion file (file comments for the specified directory) is sorted.

So as to sort any file, second and third parameters must be "%O" (file name only) and "%E" (file extension). Fourth parameter, if any, creates a new sorted file with a specified suffix added to the file name. If fourth parameter is absent or "", then the source file is sorted and replaced without confirmation.

Examples:
Script parameters
Current file
Result
"%T" any descript.ion file in the target directory is sorted
"%P", "%O", "%E", "_new" c:\path\file.txt New file c:\path\file_new.txt is created being c:\path\file.txt sorted
"%P", "%O", "%E" c:\path\file.txt File c:\path\file_new.txt is sorted and rewritten


All Scripts Total Commander TotalCmd.net PowerPro