check text file existance

hawwahawwa Member Posts: 106
edited 2004-12-13 in Navision Attain
How do I check the existance of a text file in a directory?

thank you
hawwa

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    If you would have used the search function of this forum, you would have found this thread (among others): http://www.mibuso.com/forum/viewtopic.php?t=1633 [-X
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Jelias1Jelias1 Member Posts: 35
    You can also try the Automation object Microsoft Scripting Runtime. It contains a COM object called the FileSystemObject. This gives you full control of directory/file queries and file/directory management. It contains a method called FileExists, among many other useful methods.
  • ArhontisArhontis Member Posts: 667
    :?: Why not? (copy pasted from help)
    EXISTS (File)
    Use this function to determine if a file exists.
    
    [Ok :=] File.EXISTS(Name)
    Ok
    
    Data type: boolean
    
    This return value tells you whether or not the file exists.
    
    Ok will be...
     If the file...
     
    TRUE Exists 
    FALSE Does not exist 
    
  • Jelias1Jelias1 Member Posts: 35
    One problem with C/Side's EXISTS keyword is that it does not accept wild cards. Sometimes you want to know if any file exists in a directory.
  • ArhontisArhontis Member Posts: 667
    :oops: did't got the '... of a text file in ...' right...
  • kinekine Member Posts: 12,562
    Function FExist(pPath:Text[1000]):boolean;
    var
      FileList: record 2000000022;
    begin
      FileList.SETRANGE(Path,  pPath);
      FileList.SETRANGE("Is a File",true);
      FileList.SETFILTER(Name,'*.txt');
      exit(FileList.FIND('-'));
    end;
    

    Code was written from the scratch. Can be there some mistakes... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Jelias1Jelias1 Member Posts: 35
    Wow! This works great. I'm embarrassed. :oops: I didn't know you could do that. Thanks!
Sign In or Register to comment.