Wednesday, 11 February 2015

Moving all files from a folder of specified format from one folder to other using WINAPI class in AX 2012

The following piece of code filters the source file path folder for the files with extension .docx and copies them into the destination path specified.

public void moveAllFiles()

{
    fileFilter = '\\*.docx';

    sourcePath = dialogSource.value();


    destPath = dialogDestination.value();


    [fileHandle, filename] = WinAPI::findFirstFile(sourcePath + fileFilter);


    while(fileName)

    {
        info(strFmt("%1 %2", sourcePath , fileName));

        copyFromSourceFolder = sourcePath + "\\" + fileName;

       
        copyToDestFolder = destPath + "\\" + filename;
       
        WinAPI::copyFile(copyFromSourceFolder, copyToDestFolder);

        fileName = winAPI::findNextFile(fileHandle);

    }
}

NOTE :


1) The extension format may be anything .docx .txt .xpo or anthing.

2) Here source and destination dialog fields are of type filepath.

No comments:

Post a Comment