Options

Repeat read folder

julkifli33julkifli33 Member Posts: 1,073
Hi All,
i have created how to read file and then insert to NAV
like this
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

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Try
    SFile.SETRANGE(Path,GLSetup."Import Path");
    // Name Filter
    IF SFile.FINDSET THEN
      REPEAT
         // Read the file and insert into NAV
      UNTIL SFile.Next = 0;
    
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Try
    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
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Create new global variable with Datatype record and Subtype File
    Use that for Filtering..
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Create new global variable with Datatype record and Subtype File
    Use that for Filtering..

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

    for example i just want to read every txt file start with "ABC"
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Try
    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..
  • Options
    julkifli33julkifli33 Member Posts: 1,073
    Hi Mohana,
    now it works
    thanks for your help

    final code
    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/
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    julkifli33 wrote:
    Hi Mohana,
    now it works
    thanks for your help

    \:D/ \:D/
    Welcome :D
  • Options
    colingbradleycolingbradley Member Posts: 162
    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
    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)
    //LVfile.TEXTMODE(TRUE);
    //LVFile.WRITEMODE(FALSE);
    //LVFile.OPEN(lvFile.path + name);
    

    ? How to get text lines in the file into lvString?
      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
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    (next 3 lines give error)
    //LVfile.TEXTMODE(TRUE);
    //LVFile.WRITEMODE(FALSE);
    //LVFile.OPEN(lvFile.path + name);
    

    Use LVFile1 instead of LVFile
  • Options
    colingbradleycolingbradley Member Posts: 162
    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
  • Options
    AdministratorAdministrator Member, Moderator, Administrator Posts: 2,495
    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.
  • Options
    ChowdaryChowdary Member Posts: 148
    Hi Mohana,

    How to find Dataport imported file path.

    My requirement is to find the path of the file selected by user and create an exception file in the same path

    Thanks
    Chowdary
    Pleasure in the job puts perfection in the work
Sign In or Register to comment.