CleanComments

Title CleanComments
File Name CleanComments.txt
Description Remove from descript.ion anything but "name description" pairs for existing files
Author Vochomurka
Parameters "%P"
Plugins Called file, vec
Icon
Version 1.0
Updated on 28.04.2008
args Path
local Source = Path ++ "descript.ion"

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

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

w = vec.create(1, 1)
if(w <= 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error #2")
	quit
endif

local fh = file.open(Source, "r")
local i, Str, FileName, Comment, Comms
local Quote = esc(?+\"+, ?+\+)

if(fh > 0) do
	for(not(file.eof(fh))) 
		Str = file.readstring(fh)
		if(not Str)
			continue

		FileName = word(Str, 1)

		if(file.validpath(Path ++ FileName)) do
			vec.insert(v, Comms, FileName)
			Comment = select(Str, length(FileName) - length(Str) + 1)
			vec.insert(w, Comms, Comment)
			Comms++
		else
			FileName = word(Str, 1, Quote)
			if(file.validpath(Path ++ FileName)) do
				vec.insert(v, Comms, Quote ++ FileName ++ Quote)
				Comment = select(Str, length(FileName) - length(Str) + 3)
				vec.insert(w, Comms, Comment)
				Comms++
			endif
		endif
	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error #1")
	quit
endif

file.close(fh)

if(not Comms) do
	Str = "File " ++ Source ++ " seems to contain no file comments!"
	messagebox("ok warning", Str, "CleanComment Script")
	vec.destroy(v)
	vec.destroy(w)
	quit
endif

file.delete(Source)
fh = file.open(Source, "w")

for(i = 0; i < vec.length(v); i++)
	file.writeline(fh, v[i] ++ " " ++ w[i])
endfor

file.close(fh)
vec.destroy(v)
vec.destroy(w)

All Scripts Total Commander TotalCmd.net PowerPro