Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a sample code that has worked for me in both client side as well as server side. It uses .NET namespaces to fetch the list of files in a given folder path for a given pattern.</p> <p>You can modify this to create your own server side version of <em>FindFirstFile</em> method.</p> <p><strong><em>X++ Code</em></strong></p> <pre><code>static container findMatchingFiles( str _folderPath , str _filePattern = '*.*') { System.IO.DirectoryInfo directory; System.IO.FileInfo[] files; System.IO.FileInfo file; InteropPermission permission; str fileName; counter filesCount; counter loop; container mathchingFiles; ; permission = new InteropPermission(InteropKind::ClrInterop); permission.assert(); directory = new System.IO.DirectoryInfo(_folderPath); files = directory.GetFiles(_filePattern); filesCount = files.get_Length(); for (loop = 0; loop &lt; filesCount; loop++) { file = files.GetValue(loop); fileName = file.get_FullName(); mathchingFiles = conins(mathchingFiles, conlen(mathchingFiles) + 1, fileName); } CodeAccessPermission::revertAssert(); return mathchingFiles; } </code></pre> <p><strong><em>Test job</em></strong></p> <p>To test the above code, I created the following sample files in the path <code>C:\temp\Files\</code></p> <p><img src="https://i.stack.imgur.com/l124T.png" alt="List of files"></p> <p>I placed the above mentioned method in a sample class named <em>Tutorial_WinApiServer</em>. Then, created a job named <code>fetchFiles</code> with the following code.</p> <pre><code>static void fetchFiles(Args _args) { container files; counter loop; str fileName; ; files = Tutorial_WinApiServer::findMatchingFiles(@'C:\temp\Files', '*.txt'); for (loop = 1; loop &lt;= conlen(files); loop++) { fileName = conpeek(files, loop); info(fileName); } } </code></pre> <p>Executing the job gave the following output.</p> <p><img src="https://i.stack.imgur.com/Ui4l8.png" alt="Job Output 1"></p> <p>After changing the file pattern to <strong>F*.*</strong>, the job produced the following output.</p> <p><img src="https://i.stack.imgur.com/U3Qur.png" alt="Job Output 2"></p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload