List of files from a directory ordered by date
Aquir
Member Posts: 23
How can I get a list of files from directory ordered by date in NAV? I can't use the File virtual table because there is no key for the date. I've tried with DotNet but implementing the IComparer interface is far too complicated for me.
Any ideas?
Cheers
Any ideas?
Cheers
0
Best Answer
-
Well, I'm not a dotnet expert myself but you could use the trick by creating a temporary table.
By that I mean that you create a new table with field path and date. Then you create keys for both fields.
Now to the trick. You don't really want to waste a table license on this BUT if you only use the table as a temporary table you don't need to assign the table in the licens
Here is an example I did in NAV 2013 R2 containing one codeunit and table:OBJECT Table 93000 Temp File List { OBJECT-PROPERTIES { Date=15-12-28; Time=18:35:15; Modified=Yes; Version List=; } PROPERTIES { } FIELDS { { 1 ; ;Filepath ;Text200 } { 2 ; ;Date ;Date } } KEYS { { ;Filepath ;Clustered=Yes } { ;Date } } FIELDGROUPS { } CODE { BEGIN END. } } OBJECT Codeunit 93000 Temp File List Creator { OBJECT-PROPERTIES { Date=15-12-28; Time=18:47:09; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN LoadList('C:\Temp'); ShowDateSortedList; MESSAGE('Done'); END; } CODE { VAR TempFileList@1000000000 : TEMPORARY Record 93000; VirtualFile@1000000001 : Record 2000000022; PROCEDURE LoadList@1000000001(Path@1000000000 : Text[1024]); VAR DotNetPath@1000000001 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Path"; BEGIN VirtualFile.SETRANGE("Is a file", TRUE); VirtualFile.SETRANGE(Path, Path); IF NOT VirtualFile.FINDSET THEN EXIT; REPEAT TempFileList.INIT; TempFileList.Filepath := DotNetPath.Combine(VirtualFile.Path, VirtualFile.Name); TempFileList.Date := VirtualFile.Date; TempFileList.INSERT; UNTIL VirtualFile.NEXT = 0; END; PROCEDURE ShowDateSortedList@1000000003(); BEGIN TempFileList.SETCURRENTKEY(Date); IF NOT TempFileList.FINDSET THEN EXIT; REPEAT IF NOT CONFIRM('%1 %2',FALSE, TempFileList.Date, TempFileList.Filepath) THEN ERROR('Aborts...'); UNTIL TempFileList.NEXT = 0; END; BEGIN END. } }
Hello IT, have you tried to turn it off and on?
Have you checked the cables?
Have you released the filters?
http://www.navfreak.com5
Answers
-
Well, I'm not a dotnet expert myself but you could use the trick by creating a temporary table.
By that I mean that you create a new table with field path and date. Then you create keys for both fields.
Now to the trick. You don't really want to waste a table license on this BUT if you only use the table as a temporary table you don't need to assign the table in the licens
Here is an example I did in NAV 2013 R2 containing one codeunit and table:OBJECT Table 93000 Temp File List { OBJECT-PROPERTIES { Date=15-12-28; Time=18:35:15; Modified=Yes; Version List=; } PROPERTIES { } FIELDS { { 1 ; ;Filepath ;Text200 } { 2 ; ;Date ;Date } } KEYS { { ;Filepath ;Clustered=Yes } { ;Date } } FIELDGROUPS { } CODE { BEGIN END. } } OBJECT Codeunit 93000 Temp File List Creator { OBJECT-PROPERTIES { Date=15-12-28; Time=18:47:09; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN LoadList('C:\Temp'); ShowDateSortedList; MESSAGE('Done'); END; } CODE { VAR TempFileList@1000000000 : TEMPORARY Record 93000; VirtualFile@1000000001 : Record 2000000022; PROCEDURE LoadList@1000000001(Path@1000000000 : Text[1024]); VAR DotNetPath@1000000001 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Path"; BEGIN VirtualFile.SETRANGE("Is a file", TRUE); VirtualFile.SETRANGE(Path, Path); IF NOT VirtualFile.FINDSET THEN EXIT; REPEAT TempFileList.INIT; TempFileList.Filepath := DotNetPath.Combine(VirtualFile.Path, VirtualFile.Name); TempFileList.Date := VirtualFile.Date; TempFileList.INSERT; UNTIL VirtualFile.NEXT = 0; END; PROCEDURE ShowDateSortedList@1000000003(); BEGIN TempFileList.SETCURRENTKEY(Date); IF NOT TempFileList.FINDSET THEN EXIT; REPEAT IF NOT CONFIRM('%1 %2',FALSE, TempFileList.Date, TempFileList.Filepath) THEN ERROR('Aborts...'); UNTIL TempFileList.NEXT = 0; END; BEGIN END. } }
Hello IT, have you tried to turn it off and on?
Have you checked the cables?
Have you released the filters?
http://www.navfreak.com5 -
By date as in, creation or modified date of the file itself?0
-
Hi, thanks! I've used the temporary table method at the end...even for ≈35k files it was fine!0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

