There is an application that will generate CSV files for me with names in the following format:
FileYYYYMMDDHHMMSS.CSV
These files will be placed into a directory.
What I would like to do is monitor the directory, identify a file and read the earliest version, then subsequent versions if more than one example, process the data and then pass the file into a saved folder.
Does anyone have an example of this sort of process working that I could crib or add to?
Thanks
tim
0
Comments
Freelance Dynamics AX
Blog : http://axnmaia.wordpress.com/
If you are sure no other files will be in this folder, then no need to filter for CSV.
You need to consider if a file fails to Import, move it to a new location, this will cover any non csv files as well.
Use validation within the dataport, if it fails we will move the file.
Put code like this into a report, don't use REPEAT UNTIL, just call the report via, Job Scheduler, Import one file at a time.
Make a report with integer dataItem Number CONST(1)
Code something like this
FromPath := 'C:\MyFiles\';
ToPath := 'C:\MyFiles\History\';
ErrorPath := 'C:\MyFiles\Errors\';
// This is a Variable Type = Record and Name = File
ImportFiles.SETRANGE(Path,FromPath);
ImportFiles.SETRANGE("Is a file",TRUE);
IF ImportFiles.FIND('-')THEN BEGIN
FromFileName := FromPath + ImportFiles.Name;
ToFileName := ToPath + ImportFiles.Name;
ErrorFileName := ErrorPath + ImportFiles.Name;
IF FILE.EXISTS(FromFileName)THEN BEGIN
// This is a Variable Type = Dataport and Name = YourDataport
CLEAR(MyDataport);
MyDataPort.IMPORT := TRUE;
MyDataport.FILENAME := FromFileName;
// Commit after the Import is required for Runmodal
IF MyDataport.RUNMODAL THEN BEGIN
COMMIT;
FILE.RENAME(FromFileName,ToFileName);
END ELSE
FILE.RENAME(FromFileName,ErrorFileName);
// If runmodal failed we move the file to error location
// to allow other files to be Imported
END;
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
=D>
Tim
Is there any code that you can use in this process that allows you to define how you want to sort the files before reading it. I need to sort by the Date Modified field otherwise the whole routine will fall over but can't work out how to get Navision to define how the folder is sorted
Create a Temp table. Copy data from file virtual table to temp table. Then sort temp table the way you want.
Freelance Dynamics AX
Blog : http://axnmaia.wordpress.com/