Problem Finding Record in File Table

matttraxmatttrax Member Posts: 2,309
This doesn't lend itself to an easily searchable solution as File, Record, and Table are a little too common on these forums :D

If I have this code:
FileRec.SETRANGE(Path, 'C:\');
FileRec.SETRANGE("Is a File", TRUE);
IF FileRec.FINDFIRST THEN
  REPEAT
    IF FileRec.Name = 'XXX.ext' THEN
      MESSAGE('Found It!!');
  UNTIL FileRec.NEXT = 0;
it will display the message.

But if I have this code:
FileRec.SETRANGE(Path, 'C:\');
FileRec.SETRANGE("Is a File", TRUE);
FileRec.SETRANGE(Name, 'XXX.ext');
IF FileRec.FINDFIRST THEN
  REPEAT
    MESSAGE('Found It!!');
  UNTIL FileRec.NEXT = 0;
it will not find any records and nothing is displayed.

Am I missing something about the File table? Can I not filter on Name to see if the file I want is there? I've tried SETRANGE, SETFILTER, and all manner of filter strings, but cannot get the second example to work.

Thanks for the help.

Comments

  • garakgarak Member Posts: 3,263
    1. don't use findfirst for an loop ;-)
    2. try this:
    FileRec.reset;
    FileRec.SETRANGE(Path,'C:\');
    FileRec.SETRANGE("Is a File",TRUE);
    FileRec.SETfilter(Name,'@XXX.ext');  //or @*xxx.* for all files with xxx in his name
    if FileRec.FINDset then begin
      REPEAT
        MESSAGE('Found It!!');
      UNTIL FileRec.NEXT = 0;
    end;
    

    Regards
    Do you make it right, it works too!
  • matttraxmatttrax Member Posts: 2,309
    I wasn't originally using a loop, so that's why the FINDFIRST was still in there. I was only expecting one record to be returned.

    I have to say, I am really confused. I know the @ ignores capitalization. But I even copied the entire file name directly from Windows explorer and tried to filter on that and got nothing. Yet with the @ it works.

    Why does '@XXX.ext' return a record when 'XXX.ext' does not and the file name is actually 'XXX.ext' ?? ](*,)
  • matttraxmatttrax Member Posts: 2,309
    So I decided just use the File.EXISTS command, but I'm still curious as to why you have to use the @ for the previous example to work.
  • GauravSharma21GauravSharma21 Member Posts: 7
    FileRec.SETRANGE(Path, 'C:\');
    FileRec.SETRANGE("Is a File", TRUE);
    IF FileRec.FINDFIRST THEN
      REPEAT
        IF FileRec.Name = 'XXX.ext' THEN
          MESSAGE('Found It!!');
      UNTIL FileRec.NEXT = 0;
    
    Mattrax,
    logically the above code should work, but the file name is case sensitive so try to give the file name exactly as same as stored in the FileRec table. hope it works then or alternatively use FILE.EXISTS(FilePath) as a last option... 8)
  • matttraxmatttrax Member Posts: 2,309
    As I stated before, I used the exact file name. Compared the lengths to make sure there weren't some weird characters in there that I couldn't see for some reason. Also compared each character of the string.

    So if the field contains X, a filter of X does not work, but @X does.
  • garakgarak Member Posts: 3,263
    on a local database (without a serverconnection) it works without the @.
    On a serverconnection i found out for some years that i must use the @. Why? Never searched for the reason ..... Sorry. Maybe it's depending on the serversetting / databasesetting on the server (Codepage).
    Do you make it right, it works too!
Sign In or Register to comment.