File searches in Navision

lgoodinlgoodin Member Posts: 6
edited 2005-12-11 in Navision Attain
Is there a way to do a file search with a standard Navision data type?
I looked at the functions and methods in the Navision 'File' data type and couldn't see a way to do this.

What I need to accomplish is this:
When the user runs a dataport and types in the filename to import/export to, instead of typing in c:\temp\data.txt, they would type in c:\temp\*.txt.
At this point the dataport needs to do a search in the c:\temp directory and find the first file with a .txt extension and continue processing using that file.
Is there an easy way to do this?

Comments

  • WaldoWaldo Member Posts: 3,412
    You should use the virtual table 'File' en set ranges until you are in the right directory. Here is an example:
    recFile is a variable of record 'File'
    
    CLEAR(recFile);
    recFile.RESET;
    recFile.SETRANGE(Path, ltxtDirectory + '\');
    recFile.SETRANGE("Is a file", TRUE);
    
    IF (recFile.FIND('-') = TRUE) THEN BEGIN
      REPEAT
      ...
      UNTIL(recFile.NEXT = 0);
    

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • StephenGStephenG Member Posts: 99
    You could also look at Codeunit 412 Common Dialog Management
    Answer the question and wait for the answer.
  • evanscheersevanscheers Member Posts: 4
    Waldo wrote:
    You should use the virtual table 'File' en set ranges until you are in the right directory. Here is an example:
    [code]
    Hi Waldo,
    Is there a simple way to search for a file through subdirectory's
    I now use a shell command to run a batchfile with:
    dir g:\secr\word\*cToSearch*.doc/s/b >c:\dirlist.txt
    (a dos box is showing, not so nice)
    and import the results (dirlist.txt) in a temporay table. with a dataport.

    Eric
  • WaldoWaldo Member Posts: 3,412
    When you use the code I showed you, you see that the table "File" contains a field "Is a file". When this is false, I suppose it is a directory.

    Now, when there are an unlimited amount of directories, you should have a recursive function, and I don't really know C/SIDE can do such things (never tried).

    I hope this answer is sufficient...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • brebre Member Posts: 19
    Waldo wrote:
    You should use the virtual table 'File' en set ranges until you are in the right directory. Here is an example:
    recFile is a variable of record 'File'
    
    CLEAR(recFile);
    recFile.RESET;
    recFile.SETRANGE(Path, ltxtDirectory + '\');
    recFile.SETRANGE("Is a file", TRUE);
    
    IF (recFile.FIND('-') = TRUE) THEN BEGIN
      REPEAT
      ...
      UNTIL(recFile.NEXT = 0);
    

    But as a sample: i have different files inside a directory, like *.txt, *.rtf, etc. If i want to filter out only *.txt, how can i do this?

    recFile.SETRANGE(Name, '*.txt') shows no result.

    If i use it w/o 'SETRANGE(Name....)', i get ALL files.

    Any idea for this?
    .
  • WaldoWaldo Member Posts: 3,412
    Try this (didn't try it, so not sure it'll work ...):
    recFile.SETFILTER(Name,'*%1','.txt');
    //*** or this
    recFile.SETFILTER(Name,'*.txt');
    

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • hawwahawwa Member Posts: 106
    The refFile.SETFILTER (Name, varName); work but is case sensitive. For example,
    recFile.SETFILTER(Name, 'abc*');


    cannot find the file with file name ABCD.txt but can get file with file name abcd.txt.

    How to make the SETFILTER case-insensitive ?

    Thanks,
    Hawwa
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Use

    SETFILTER(FIELD, '*@value*');

    The @ makes it case-insensitive
  • hawwahawwa Member Posts: 106
    The @ is not able to make the SETFILTER case-insensitive. Is there any setting that I missed out.


    recFile.SETRANGE(Path, 'C\PO\');
    recFile.SETRANGE("Is a file", TRUE);
    recFile.SETFILTER(Name, '@po*');

    Thanks.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I should realy work.

    What you can try is to make a new form on the file table and set your filter.

    Then you can try visualy if the filter is correct.

    The file table is somewhat odd; it is only filled after setting a filter.

    Maybe you should make code like:

    file.setrange("is a file" true);
    if find.find('-') then repeat
    fileexists := strpos('PO', UPPERCASE(File.name)) <> 0;
    until file.next = 0;

    Suc6.

    Marq
  • hawwahawwa Member Posts: 106
    Hi Mark,

    I have tried the File table with a List Form. No matter what combination of filter I used, it is still case-sensitiv for the Name field.
  • ara3nara3n Member Posts: 9,256
    try to put a @ infront of your filter. It makes it case insensitive.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • hawwahawwa Member Posts: 106
    Tried already but not work.

    recFile.SETRANGE(Path, 'C\PO\');
    recFile.SETRANGE("Is a file", TRUE);
    recFile.SETFILTER(Name, '@po*');
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This works for me:
    recFile.SETRANGE(Path, 'c:\delme');
    recFile.SETRANGE("Is a file", TRUE); 
    recFile.SETFILTER(Name, '@se*');
    IF recFile.FIND('-') THEN
      REPEAT
        MESSAGE(recFile.Name);
      UNTIL recFile.NEXT = 0;
    

    The messages I got are "setup.ini", "Setup.exe", "SETUP.LST".
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • hawwahawwa Member Posts: 106
    Luc Van Dyck,

    That doesn't work for me. What version of Navision are you using ? I am using Navision Version 4.0 running on SQL Server 2000.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    I used MBS-Navision W1 3.70, local Navision database.

    Tested is now on MBS-Navision W1 4.0, local Navision database: works also.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • wakestarwakestar Member Posts: 207
    Hi

    I just wanted to have a look at this table but the table is empty. :-s
    I created a new Tabular-Type Form using the 'File'-Table and saved the form without any filters.

    Working with Navision 3.7

    :-k
  • wakestarwakestar Member Posts: 207
    wakestar wrote:
    Hi

    I just wanted to have a look at this table but the table is empty. :-s
    I created a new Tabular-Type Form using the 'File'-Table and saved the form without any filters.

    Working with Navision 3.7

    :-k


    oops, Mark wrote it already. :oops: After setting a constant filter on 'Path' the form shows the records.

    thanks
  • brebre Member Posts: 19
    hawwa wrote:
    Tried already but not work.

    recFile.SETRANGE(Path, 'C\PO\');
    recFile.SETRANGE("Is a file", TRUE);
    recFile.SETFILTER(Name, '@po*');

    Try this, it works for me in V3.70

    recFile.SETRANGE(Path, 'C\PO\');
    recFile.SETRANGE("Is a file", TRUE);
    recFile.SETFILTER(Name, '%1', '@po*.*');
Sign In or Register to comment.