reading file names in directory caching problem

davmac1davmac1 Member Posts: 1,283
I have a routine in a report program that reads the file names in a Windows directory using the Navision virtual FILE. It moves processed files to another directory.
The problem I have is that when I rerun the report which runs the routine again, it reads the file names from the directory that existed at the time of the first read, even though they are no longer there.
The only fix I have found is to exit Navision and get back in - which is not practical for turning over to a non-technaical user.
Is there any way of forcing Navision to read the current contents of a Windows directory?

Comments

  • matttraxmatttrax Member Posts: 2,309
    I've found that the EXISTS function works much better than the virtual file table. You could possible loop through the records in the file table and call the EXISTS function on that filename before doing any processing.
  • davmac1davmac1 Member Posts: 1,283
    My main problem is that it is not reading any new files hat have been added to the directory.

    A workaround ay be to read another directory and see if that clears the cache on the directory I want.
  • SavatageSavatage Member Posts: 7,142
    How are you moving the files? perhaps you need to clear or reset the function once done.

    We use this for dataports once the import is completed. Make sure it's closed - Use File.Copy & then Finally Erase The Orig.

    CurrFile.CLOSE;
    SavedFileName := FORMAT(WORKDATE,0,'<Year4>'+'-'+'<Month Text,3>'+'-'+'<Day,2>')+'.txt';
    FILE.COPY(CurrReport.FILENAME,FilePath+SavedFileName);
    ERASE(CurrReport.FILENAME);
  • davmac1davmac1 Member Posts: 1,283
    Yes - doing FILE.COPY followed by FILE.ERASE
    The report exits when complete.
    Then if we run the report again reading the same directory, it "reads" the old file names that were deleted, and does not read any new files that were added.
    It acts like it read the contents of the directory into cache and reads the cached directory. Since the report object was closed and the rerun, it seems lke it is a NAV client issue.
  • FDickschatFDickschat Member Posts: 380
    We had the same problem. A report reads the table file, processes the files and copies/deletes them. When new files were stored the report would not see them.

    There are 2 solutions:
    1) Quick and Dirty (but very easy to implement)
    Before reading the correct folder place the filter onto another existing folder, do a findfirst and only after that process your folder. NAV only has one cache for the table File. So the cache is always cleared every time you read another folder.

    2) The correct one (much more work to implement):
    Move the code that reads the table File and all subsequent code into a codeunit. In your report create a local variable for that codeunit and run it. This also solves it as local vaiables are always destroyed (and the file list cache cleared) when the report finishes.

    Best regards, Frank
    Frank Dickschat
    FD Consulting
  • kinekine Member Posts: 12,562
    This is old problem. Just search for File table posts and you will see, that you need to change the filter to something different and back to see changes in the directory.

    (as FDickschat wrote in his post)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • davmac1davmac1 Member Posts: 1,283
    thanks - that worked.

    the problem with searching the forum is that you have to put in the words that exactly match those used before.
    google is usually better, but in this case did not come up with the answer
Sign In or Register to comment.