OL Learn

Script - count number of files

Hi

Anybody who has a script to count number of files in a specific folder ?
Need a script cause the plugin “Folder listen” does not work on an empty folder - it only returns info if the folder is not empty.

I need to stop a specific process or do noting if a folder is full of files.

What you could do, without writing a script, is to have a local variable foundFiles that you setup to false before the call to the Folder listing plugin.

The call to Folder listing should be in a branch. After the Folder listing plugin, you set the variable to true.

Then, back to your main branch, you setup a condition on the content of the local variable foundFiles.
If it is set to true, you did have files in the folder.
If it is still set to false, there was nothing found.

Hope that helps.

1 Like

FYI, I just made an improvement request to add an option, allowing the Folder Listing plugin to continue with a file count of 0, so you can setup different action in case of 0 files found.

This has been rejected but a better solution will be devise. Most likely a condition based on the file count.

Super thanks for the help…

You can also use a vbscript, maybe as a condition or only as an action.

Following script may give you the idea of how to do it

set fso = CreateObject("Scripting.FileSystemObject")

checkPath = "C:\PLANETPRESS\"
file_extension = "csv"

set oFolder = fso.GetFolder(checkPath)
set colFiles = oFolder.Files

i = 0
For Each oFile in colFiles
 if(InStr(oFile.Name, "." & file_extension) <> 0) i = i + 1
Next

if(i > 0) then
 Watch.Log "Found files (amount: " & i & ")",2
 'Script.ReturnValue = 1
else
 Watch.Log "No CSV files in folder",2
 'Script.ReturnValue = 0
end if

This code checks if specific files (in this example .csv files) exists in a folder.

Hope that helps.

Perfect thanks - just what is was looking for.