WinCC Unified V18: List files and folders structures with JavaScript

Опубликовано: 28 Октябрь 2024
на канале: DerHecht4.0
9,431
40

In this Video I want to show you how you can browsing files in the directory with the new JavaScript function HMIRuntime.FileSystem.Browse

00:00 Intro
00:20 What is possible with this function
01:29 How does it work

//JS code
Screen.Items("txtFolders").Text = '';//reset Output Textbox folder
Screen.Items("txtFiles").Text = '';//rest Output Textbox Files

let mypath = Screen.Items("IOPath").ProcessValue; //your Path like D:/
let filter= Screen.Items("IOFilter").ProcessValue; //filter with wildcards like *txt or ??lo for flow
let rec = Screen.Items("SWRecursive").IsAlternateState; //list all files in sub folders

HMIRuntime.FileSystem.Browse(mypath, filter, rec)
.then( function(pathnames) {
for ( let i=0; i "smaller-than sign" pathnames.length; i++) {
let path = pathnames[i];
if ( HMIRuntime.FileSystem.IsDirectory(path) )
{
/* found directory */
Screen.Items("txtFolders").Text += path + "\r\n";
HMIRuntime.Trace('found directory : ' + path);
}
else
{
/* found file */
Screen.Items("txtFiles").Text += path + "\r\n";
HMIRuntime.Trace('found file : ' + path);
}
}
}).catch(function(errorcode) {
let errorMsg = HMIRuntime.GetDetailedErrorDescription(errorcode);
Screen.Items("txtFiles").Text += errorMsg + "\r\n";
HMIRuntime.Trace(' Browse error: ' + errorMsg);
});

#DerHecht #WinCC #Unified #TIAPortal #V18

Music from Unicorn Heads- Drifting at 432 Hz    • Unicorn Heads - Drifting at 432 Hz