READ MULTIPLE TXT FILES FROM A DIRECTORY

leugim
Member Posts: 93
hi all, some help is needed
one of our customers has a software which creates a file in a predefined path periodically (i. e. every 5 mins)
the name of the files follows the rule: txtFileName_yymmdd_hhmmss
we thougth to create a new directory for "processed files", to copy there all txt files processed in Nav. the processed files will be deleted from original path, in order to have here as less files as possible
we are looking for some code to read the name of the files in a directory from within Navision with some report or loop code from a codeunit, but we don't know how to return the name of the files, because never two files will be named equally due to date & time..
hope you understand what we want to explain...
regards
one of our customers has a software which creates a file in a predefined path periodically (i. e. every 5 mins)
the name of the files follows the rule: txtFileName_yymmdd_hhmmss
we thougth to create a new directory for "processed files", to copy there all txt files processed in Nav. the processed files will be deleted from original path, in order to have here as less files as possible
we are looking for some code to read the name of the files in a directory from within Navision with some report or loop code from a codeunit, but we don't know how to return the name of the files, because never two files will be named equally due to date & time..
hope you understand what we want to explain...
regards
_______________
so far, so good
so far, so good
0
Answers
-
Hi
In NAV exists a virtual table "File"
WITH recFile DO BEGIN
RESET;
SETRANGE(Path,strPath);
SETRANGE("Is a file",TRUE);
IF FIND('-') THEN
REPEAT
MESSAGE(Name);
UNTIL NEXT = 0;
END;1 -
wow... perfect!! that's what we were looking for
THAAAAAAAAAAANKS A LOT!!! \:D/
regards_______________
so far, so good0 -
Does the virtual Table File exist in NAV 4.0???0
-
yes, it existed for a while now. Probably from the beginning.0
-
Another way to do this is the next :
Since Navision can't loop trough all the files in a folder the filenames are stored in a 'Microsoft Scripting Runtime'.Dictionary ( the FilesCol object), using the VBScript.
This vbScript gives the dictionary an integer and text value. The integer to loop, the text is the filename.
I found the vbScript here on Mibuso to loop trough folders : http://www.mibuso.com/forum/viewtopic.php?f=5&t=7855&hilit=folders
Just to know there are others ways ...
Variables are : ( all of type automation )
FilesCol : 'Microsoft Scripting Runtime'.Dictionary
Script : 'Microsoft Script Control 1.0'.ScriptControl
WHSFileSystemObject : 'Windows Script Host Object Model'.FileSystemObject
WHSFolder : 'Windows Script Host Object Model'.Folder
WHSFile : 'Windows Script Host Object Model'.FileIF ISCLEAR(WHSFileSystemObject) THEN CREATE(WHSFileSystemObject); // If the folder does not exist, exit IF NOT WHSFileSystemObject.FolderExists(ltxtFolder) THEN BEGIN CLEAR(WHSFileSystemObject); EXIT; END; WHSFolder := WHSFileSystemObject.GetFolder(ltxtFolder); WHSFiles := WHSFolder.Files; IF ISCLEAR(FilesCol) THEN CREATE(FilesCol); // ======================================================================== // Use a VBScript to fill a 'Microsoft Scripting Runtime'.Dictionary IF ISCLEAR(Script) THEN CREATE(Script); Script.Language := 'VBScript'; //variable LautFolders is visible in script as FoldersByName Script.AddObject('FilesByName', WHSFiles); //variable FoldersCol is visible in script as FoldersById Script.AddObject('FilesById', FilesCol); //copy objects using VBScript txtCR := ''; txtCR[1] := 13; txtCode := 'dim f1' + txtCR + 'For Each f1 in FilesByName' + txtCR + ' FilesById.Add (FilesById.Count+1), f1' + txtCR + 'Next' + txtCR; Script.ExecuteStatement(txtCode); CLEAR(Script); // ======================================================================== FOR i := 1 TO FilesCol.Count() DO BEGIN WHSFile := FilesCol.Item(i); ltxtFileName := WHSFolder.Path + '\' + WHSFile.Name; // ========================== // Here you do what you want to do with the file... // ========================== END; CLEAR(FilesCol); CLEAR(WHSFileSystemObject);
-1
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