How to import multiple file from a folder?

Hello,

Currently we can import a file (acsii) into AX. But can we search all file in 1 folder to import the each file 1 by 1?

AsciiIO asciiIO;

asciiIO = new AsciiIO(filePath, ‘R’);
asciiIO.inFieldDelimiter("\n");
asciiIO.inRecordDelimiter("\n");

while (asciiIO.status() == IO_Status::Ok) {

line = conpeek(asciiIO.read(), 1);

}

Hi Kenl

This will help to build a list of files in a folder. Then you can load the file one by one.

container createListOfFiles(FilePath _path = path, FileNameType _pattern = pattern)
{
System.Array files;
int fileCount;
int i;
str nextFile;

new InteropPermission(InteropKind::ClrInterop).assert();

info(strfmt(‘Search in: %1 %2’, _path, _pattern));

listOfFiles = connull();
actIx = 0;
files = System.IO.Directory::GetFiles(_path, _pattern);
if (files)
{
fileCount = files.get_Length();
info(strFmt(‘Number of files in directory: %1’, fileCount));
for(i=0; i < fileCount; i++)
{
nextFile = files.GetValue(i);
listOfFiles += nextFile;
}
}

CodeAccessPermission::revertAssert();

info(strFmt(‘Files count: %1’, conlen(listOfFiles)));

return listOfFiles;
}

Best Regards

Fensmark

Thank you very much for the solution.

I use another method to get it.

[handle, filename] = WINAPI::findFirstFile(filepath + “\*.txt”);

while (fileName != “”)
{
try {
this.executeFile(fullFileName);
numFileImport++;

}

filename = WinAPI::findNextFile(handle);

}

Hi Kenl,

I’ve the same problem… I want to upload multiple files from one folder.

but I con’t understand the above coding shall you post full method & steps I will understand…

Thanks in advance

Regards

Rajab.

Hi Rajab,

To get inspiration have a look under SysHelpSetupWizard class → getLanguages method.

Regards,