mibuso.com

Microsoft Business Solutions online community
It is currently Mon May 20, 2013 7:27 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: [Solved] Repeat read folder
PostPosted: Wed Feb 08, 2012 11:44 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
Hi All,
i have created how to read file and then insert to NAV
like this
Code: Select all
SFile.TEXTMODE(TRUE);
SFile.WRITEMODE(FALSE);
SFile.OPEN(GLSetup."Import Path" + 'TestItem.txt');
  REPEAT
   //codeinsert to NAV
  UNTIL SFile.POS = SFile.LEN;


but this one is I did it using hardcode
which is only can read TestItem.txt
how to read all the txt file in GLSetup."Import Path" ??
and how to read only the file which start with "ABC" ?
thanks


Top
 Profile E-mail  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 11:51 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4224
Location: New Delhi
Country: India (in)
Try

Code: Select all
SFile.SETRANGE(Path,GLSetup."Import Path");
// Name Filter
IF SFile.FINDSET THEN
  REPEAT
     // Read the file and insert into NAV
  UNTIL SFile.Next = 0;

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/


Top
 Profile  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 11:53 am 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
mohana_cse06 wrote:
Try

Code: Select all
SFile.SETRANGE(Path,GLSetup."Import Path");
// Name Filter
IF SFile.FINDSET THEN
  REPEAT
     // Read the file and insert into NAV
  UNTIL SFile.Next = 0;


SFile is datatype file, is it?
i cant do setrange


Top
 Profile E-mail  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 12:16 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4224
Location: New Delhi
Country: India (in)
Create new global variable with Datatype record and Subtype File
Use that for Filtering..

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/


Top
 Profile  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 3:40 pm 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
mohana_cse06 wrote:
Create new global variable with Datatype record and Subtype File
Use that for Filtering..


and how about to change the file name ?
this part -->
Code: Select all
SFile.OPEN(GLSetup."Import Path" + 'TestItem.txt');


for example i just want to read every txt file start with "ABC"


Top
 Profile E-mail  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 4:10 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4224
Location: New Delhi
Country: India (in)
mohana_cse06 wrote:
Try

Code: Select all
SFile.SETRANGE(Path,GLSetup."Import Path");
// Name Filter
IF SFile.FINDSET THEN
  REPEAT
     // Read the file and insert into NAV
  UNTIL SFile.Next = 0;


Add your Name filter just below Path..

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/


Top
 Profile  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 4:53 pm 
Offline

Joined: Wed Sep 29, 2010 3:18 am
Posts: 764
Country: Australia (au)
Hi Mohana,
now it works
thanks for your help

final code
Code: Select all

GLSetup.GET;
SFile1.SETRANGE(Path,GLSetup."Import Path");
SFile1.SETRANGE("Is a file",TRUE);
IF SFile1.FINDSET THEN
REPEAT
SFile.TEXTMODE(TRUE);
SFile.WRITEMODE(FALSE);
SFile.OPEN(GLSetup."Import Path" + SFile1.Name);
  REPEAT
.
.
.


\:D/ \:D/


Top
 Profile E-mail  
 
 Post subject: Re: Repeat read folder
PostPosted: Wed Feb 08, 2012 4:56 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4224
Location: New Delhi
Country: India (in)
julkifli33 wrote:
Hi Mohana,
now it works
thanks for your help

\:D/ \:D/

Welcome :D

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/


Top
 Profile  
 
 Post subject: Re: Repeat read folder
PostPosted: Thu Feb 23, 2012 2:24 pm 
Offline

Joined: Fri Oct 28, 2005 1:46 pm
Posts: 127
Location: London
Country: United Kingdom (uk)
I am getting errors using either global or local variable for the record type File
the code so far is:
Local Vars:
Name DataType Subtype Length
Code: Select all
lvFile                   Record   File   
lvField           Text                         100
lvWebImport   Record   Web Import 1   
lvString           Text                         1000
lvStringLine         Text                             1000
lvFile1           File      

CLEAR(lvFile);
lvFile.setrange(path,'C:\temp\');
lvfile.setfilter(name, '%1' , 'test*.txt');
if lvFile.FINDSET THEN BEGIN


(next 3 lines give error)
Code: Select all
//LVfile.TEXTMODE(TRUE);
//LVFile.WRITEMODE(FALSE);
//LVFile.OPEN(lvFile.path + name);


? How to get text lines in the file into lvString?
Code: Select all
  with lvString do
  repeat
  lvField[1] := copystr(lvStringLine,1,20);
  etc
  until lvString.next = 0;
 
end;


I am obviously missing something key here, I can find my .txt files, I then need to read each file and for each line in the file insert to a field in a table.

_________________
Experience is what you get when you hoped to get money


Top
 Profile E-mail WWW  
 
 Post subject: Re: Repeat read folder
PostPosted: Thu Feb 23, 2012 2:43 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Sep 02, 2008 8:37 am
Posts: 4224
Location: New Delhi
Country: India (in)
colingbradley wrote:
(next 3 lines give error)
Code: Select all
//LVfile.TEXTMODE(TRUE);
//LVFile.WRITEMODE(FALSE);
//LVFile.OPEN(lvFile.path + name);




Use LVFile1 instead of LVFile

_________________
-Mohana
http://mibuso.com/blogs/mohana
http://mohana-dynamicsnav.blogspot.in/


Top
 Profile  
 
 Post subject: Re: Repeat read folder
PostPosted: Thu Feb 23, 2012 2:59 pm 
Offline

Joined: Fri Oct 28, 2005 1:46 pm
Posts: 127
Location: London
Country: United Kingdom (uk)
You are correct, these work.
LVfile1.TEXTMODE(TRUE);
LVFile1.WRITEMODE(FALSE);
LVFile1.OPEN(lvFile.path + lvfile.name);

next question is how do I read the data within lvFile1 into a table?

_________________
Experience is what you get when you hoped to get money


Top
 Profile E-mail WWW  
 
 Post subject: Re: Repeat read folder
PostPosted: Thu Feb 23, 2012 3:02 pm 
Offline
Site Admin

Joined: Sun Nov 07, 1999 8:01 am
Posts: 1900
Location: Wilrijk, Belgium
Country: Belgium (be)
colingbradley wrote:
next question is how do I read the data within lvFile1 into a table?

The topic title of this thread is "Repeat read folder", which is marked as solved. If you question is not related to this topic, then please start a new thread.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: