Check Ascending Counter

Title CheckAscCounter
File Name CheckAscCounter.txt
Description Check whether files are numbered in ascending order
Author Vochomurka
Parameters ("%P", "%O", "%E")
Plugins Called win, file, miscplugin, osd, clip
Icon
Version 1.3
Updated on 16.06.2014
args Path, Name, Ext
local hwnd = win.handle("c=TTOTAL_CMD")
local Exepath = win.exepath(hwnd)
local Len = length(Name)
local Total = file.allfiles(Path)
local mpDlgCaption = "CheckAscCounter Script"
local mpIcon = "e:\Storage\Graphics\Icons\User\Incr.ico"
local i, j, Char, mpDlgText, Prev
local Quote = esc(?+\"+, ?+\+)
local CtC = "&Copy to Clip"
local Gt = "&Go to"
Ext = "." ++ Ext

for(i = Len; i > 0; i--)
	Char = Name[i - 1]
	if(not miscplugin.is_int(Char))
		break

endfor

if(i == Len) do
	Char = "File name " ++ Name ++ Ext ++ " contains no counter"
	messagebox("ok error", Char, mpDlgCaption)
	quit
endif

Char = select(Name, i - Len)
Name = select(Name, i)
local Digits = length(Char)

for(i = 1; i <= Total; i++)
	osd.show(i ++ " / " ++ Total, "INFINITE", "30", "Arial", "-1", "255 000 000")
	Len = fill(repeat("0", Digits), i)
	Char = Path ++ Name ++ Len ++ Ext
	if(not validpath(Char)) do
		osd.hide
		mpDlgText = "First missing file is '" ++ Char ++ "'"
		local Ans = miscplugin.messagebox(1, Gt, CtC, "&Exit")
		if(Ans == Gt) do
			if(not Prev) do
				win.sendmessage(hwnd, 0x400+51, 2050, 0)
			else
				do(Exepath,"/O /S /L=" ++ Quote ++ Path ++ Prev ++ Ext ++ Quote)
				*keys {down}
			endif
		elseif(Ans == CtC) do
			clip.set(Char)
		endif
		quit
	endif
	Prev = Name ++ Len
endfor

osd.hide
Prev = " files with ascending numbers"
Char = Quote ++ Total ++ Prev ++ Quote
do("e:\Utils\NirSoft\NirCmd\nircmd.exe", "speak text " ++ Char)
Char = "Directory '" ++ Path ++ "' contains " ++ Total ++ Prev
messagebox("ok information", Char, mpDlgCaption)

Comments:

How is it convenient to name files, especially if their order matters? Of course, with a counter, for example:

file-001
file-002
...
or
0001
0002
...

Therefore, all file names are ending with a certain quantity of numeric characters.

But at deleting, adding, or renaming files their numbering is disturbed. The script checks whether files are numbered sequentially, in ascending order, starting with 1. When the disturbance is found, the script allows either to go directly to the next file, or to copy the missing name to the clipboard. Before running the script the cursor should be placed on any file to be a "sample" to check others.

Why not use MultiRename Tool right away? Because the MultiRename Tool operation can take a great time for which Total Commander remains unavailable. For example, in one directory on my computer there are 24589 sequentially numbered files. If missing file has number, say, 24585, then there is no sense to rename all files.


Check Descending Counter

Title CheckDescCounter
File Name CheckDescCounter.txt
Description Check whether files are numbered in descending order
Author Vochomurka
Parameters ("%P", "%O", "%E")
Plugins Called win, file, miscplugin, osd, clip
Icon
Version 1.3
Updated on 16.06.2014
args Path, Name, Ext
local hwnd = win.handle("c=TTOTAL_CMD")
local Exepath = win.exepath(hwnd)
local Len = length(Name)
local Total = file.allfiles(Path)
local mpDlgCaption = "CheckDescCounter Script"
local mpIcon = "path_to_icon\Decr.ico"
local Quote = esc(?+\"+, ?+\+)
local CtC = "&Copy to Clip"
local Gt = "&Go to"
Ext = "." ++ Ext
local i, j, Char, mpDlgText, Prev

for(i = Len; i > 0; i--)
	Char = Name[i - 1]
	if(not miscplugin.is_int(Char))
		break

endfor

if(i == Len) do
	Char = "File name " ++ Name ++ Ext ++ " contains no counter"
	messagebox("ok error", Char, mpDlgCaption)
	quit
endif

Char = select(Name, i - Len)
Name = select(Name, i)
local Digits = length(Char)
local Limit = 1 ++ repeat("0", Digits)

for(i = Limit - 1; i >= Limit - Total; i--)
	Char = Limit - i
	Char = Char ++ " / " ++ Total
	osd.show(Char, "INFINITE", "30", "Arial", "-1", "255 000 000")
	Len = fill(repeat("0", Digits), i)
	Char = Path ++ Name ++ Len ++ Ext
	if(not validpath(Char)) do
		osd.unload
		mpDlgText = "First missing file is '" ++ Char ++ "'"
		local Ans = miscplugin.messagebox(1, Gt, CtC, "&Exit")
		if(Ans == Gt) do
			if(not Prev) do
				*keys {end}
			else
				do(Exepath,"/O /S /L=" ++ Quote ++ Path ++ Prev ++ Ext ++ Quote)
				*keys {up}
			endif
		elseif(Ans == CtC) do
			clip.set(Char)
		endif
		quit
	endif
	Prev = Name ++ Len
endfor

Char = "Directory '" ++ Path ++ "' contains " ++ Total ++ " files with descending numbers"
messagebox("ok information", Char, mpDlgCaption)

Comments:

The difference between previous script and this one is that the latter checks numbers in descending order:

...
file98
file99
or
...
9998
9999

Number consisting of nines is checked first.


Main Page Total Commander PowerPro