JSE_File

When copying and pasting, an invisible character can be added to the beginning of your file’s path (path). As a result, your file will not be found correctly, the most reliable solution is to copy the path manually

Introduction

The JSE_File class allows you to interact with system files through a number of methods

Duties

createDirectory(string pathDirectory): void

This method creates a directory on the system using pathDirectory as the path

JSE_File.createDirectory("C:\Users\openbee\Documents\Test\NouveauTest"); //Créer le répertoire NouveauTest

getDirectories(string directoryPath): String[]

This function allows you to obtain the name of the directories contained in the directory passed as a parameter in the form of a string list

return JSE_File.getDirectories("C:\Users\openbee\Documents\Test");

Result

[
	"C:\Users\openbee\Documents\Test\BasicTest",
	"C:\Users\openbee\Documents\Test\NouveauTest",
	"C:\Users\openbee\Documents\Test\PreviousTest"
]

getFiles(string directoryPath): String[]

This function allows you to obtain the names of the files contained in the directory passed as a parameter in the form of a string list

return JSE_File.getFiles("C:\Users\openbee\Documents\Test");

Result

[
	"C:\Users\openbee\Documents\Test\NouveauTestFile.txt",
	"C:\Users\openbee\Documents\Test\TestFile1.txt"
]

deleteFile(string filename): void

This method deletes the file whose path is passed as a parameter

JSE_File.deleteFile("C:\Users\openbee\Documents\Test\TestFile1.txt");

downloadFile(OBWebResponse wsResponse, string fileName): void

This method downloads a file contained in the OBWebResponse object passed as a parameter. This method is usually used in addition to a web service call whose result is not a string but a file specifying:

  • fileName: The path of the file that will be created after uploading
var ws = new JSE_WebService("127.0.0.1", "http", 8090);
var res = ws.send("/ws/document/file/"+INTERNAL_DOCUMENT_ID, "GET", {"Authorization" : "Bearer "+ CAPTURE_WS_TOKEN}, -1, false);
JSE_File.downloadFile(res, "C:\Users\openbee\Documents\Test\TestFromResponseDownload.pdf");

writeFile(string pPath, string pContent, string pEncoding): void

This method writes the contents of your pContent string to the specified pPath file. If the file does not exist, it is created (if the rights are sufficient), otherwise it is overwritten.

The pEncoding parameter is optional (Version 3.8.3-554).

JSE_File.writeFile("C:\Users\openbee\Documents\Test\testCSV.csv","COL1;COL2nTOTO;TITI");

The encodings available depend on the platform where the script is run. In the case of unsupported encoding, a warning message is present in the logs, as well as a list of encoding available for the platform. Examples of supported encodings: “iso-8859-13”, “utf-8”, “us-ascii” ..

readFile(string pPath, string pEncoding): String

This function allows you to read the contents of a pPath file passed as a parameter if the user’s rights allow it

The pEncoding parameter is optional (Version 3.8.3-554).

return JSE_File.readFile("C:\Users\openbee\Documents\Test\testCSV.csv");

Result

COL1;COL2
TOTO;TITI

The encodings available depend on the platform where the script is run. In the case of unsupported encoding, a warning message is present in the logs, as well as a list of encoding available for the platform. Examples of supported encodings: “iso-8859-13”, “utf-8”, “us-ascii”..

addLogMessage(string pMessage): void

This method allows you to write logs to help you find your way around your scripts. These logs will output to the file that corresponds to the client console logs. Depending on the user’s rights, these can be found:

  • [DOSSIER INSTALLATION DE LA CONSOLE]\Bin\Log\EasyCaptureUI\EASYCAPTUREMUIL_YYYYMMDD.txt
  • C:\Users\*****\AppData\Local\VirtualStore\Program Files (x86)\OpenBee\Open Bee™ Scan Capture \Console\Bin\Log\EasyCaptureUI\EASYCAPTUREMUIL_YYYYMMDD.txt
JSE_File.addLogMessage("Debut de mon script");
var a = 0;
var b = 1;
if(a == b)
	JSE_File.addLogMessage("Mes variables sont égales");
else
	JSE_File.addLogMessage("Mes variables sont inégales: a="+a+" b="+b);

Result in log file EASYCAPTUREMUIL_YYYYMMDD.txt

22/01/2020 15:17:18--INFO --[EasyCaptureUI.Services.JSEngine.OBJSEngine.addLogMessage] 
Debut de mon script
22/01/2020 15:17:18--INFO --[EasyCaptureUI.Services.JSEngine.OBJSEngine.addLogMessage] 
Mes variables sont inégales: a=0 b=1