Closed Finding a file name to use and passing it to a d'port

TimSmith
Member Posts: 36
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
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
-
You have to use the virtual table file to read all the files frol that folder. Then filter those files "File*.CSV". Sort the files by name0
-
nunomaia wrote:You have to use the virtual table file to read all the files frol that folder. Then filter those files "File*.CSV". Sort the files by name
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;Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
A BIG Thanks for the info, that really helps and I now understand how the coding works.
=D>
Tim0 -
nunomaia wrote:You have to use the virtual table file to read all the files frol that folder. Then filter those files "File*.CSV". Sort the files by name
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 sorted0 -
Directly you can’t do that.
Create a Temp table. Copy data from file virtual table to temp table. Then sort temp table the way you want.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions