Hello
I want to count files inside comic book (who are basically zip or rar file renamed)
I've noticed that, if I had a column under general\number total of files (I guess it's something like that, I have a french version), DOPUS knows how to count the files.
So I write this:
@script VBScript
Option Explicit
dim cmd, selitem
Function OnClick(ByRef clickData)
DOpus.ClearOutput
' ---------------------------------------------------------
Set cmd = clickData.func.command
cmd.deselect = false ' Prevent automatic deselection
' ---------------------------------------------------------
If clickData.func.sourcetab.selected.count = 0 Then
DOpus.Output " (none)"
Else
For Each selItem in clickData.func.sourcetab.selected
dopus.output "nombre de fichiers " & selitem.metadata.other.filecounttotal
Next
End If
' ---------------------------------------------------------
' ---------------------------------------------------------
End Function
The problem is that I've got a number only if I had previously added the column.
How can I force my script to have the data ?
You can calculate the number of files below an archive in the script without relying on file display columns:
var filePath = "C:\\My Test Folder\\Fo.ols.cbz";
var fileCount = FileCountRecursive(filePath);
DOpus.Output("File count = " + fileCount);
function FileCountRecursive(filePath) {
var fileCount = 0;
var folderEnum = DOpus.FSUtil.ReadDir(filePath, "r");
while (!folderEnum.complete) {
var folderItem = folderEnum.Next;
if (!folderItem.is_dir) {
++fileCount;
}
}
return fileCount;
}
Thanks you, I translated it in Vbscript and this is working
@script VBScript
Option Explicit
dim cmd, selitem
Function OnClick(ByRef clickData)
DOpus.ClearOutput
' ---------------------------------------------------------
Set cmd = clickData.func.command
cmd.deselect = false ' Prevent automatic deselection
' ---------------------------------------------------------
If clickData.func.sourcetab.selected.count = 0 Then
DOpus.Output " (none)"
Else
For Each selItem in clickData.func.sourcetab.selected
dopus.output "nom du fichier " & selitem & " contient " & FileCountRecursive(selitem)
Next
End If
' ---------------------------------------------------------
' ---------------------------------------------------------
End Function
function FileCountRecursive(filePath)
dim filecount: dim folderEnum: dim folderItem
Set folderEnum = DOpus.FSUtil.ReadDir(filePath,"r")
Do while (not folderEnum.complete)
set folderItem = folderEnum.Next
if not(folderItem.is_dir) then
fileCount=filecount+1
end if
loop
FileCountRecursive= fileCount
End function