Forum Discussion

automateable's avatar
automateable
Occasional Contributor
7 years ago

How to search files with different file types using aqFileSystem.FindFiles function?

How to use SearchPattern to allow searching of files with filtered file types. For example, I want to find image files with *.jpg and *.png extensions. Is this possible? thanks 

  • On a simple note,

     

    aqFileSystem.FindFiles("<your home path with backslash>", "*.jpg") returns list of jpg image files

    aqFileSystem.FindFiles("<your home path with backslash>", "*.png") returns list of png image files

     

    Additional,

     

    if you find files with some common names, you can try like below

    aqFileSystem.FindFiles("<your home path with backslash>", "*test-files*image.jpg") returns list of files matches with "*test-files*image.jpg" this pattern.

  • shankar_r's avatar
    shankar_r
    Community Hero

    On a simple note,

     

    aqFileSystem.FindFiles("<your home path with backslash>", "*.jpg") returns list of jpg image files

    aqFileSystem.FindFiles("<your home path with backslash>", "*.png") returns list of png image files

     

    Additional,

     

    if you find files with some common names, you can try like below

    aqFileSystem.FindFiles("<your home path with backslash>", "*test-files*image.jpg") returns list of files matches with "*test-files*image.jpg" this pattern.

  • I'm doing it with two calls

    function  ListFiles(PathWithBackSlash, pattern);
    var
      foundFiles;
      afile;
    begin
      aqString.ListSeparator := #13; 
      result := '';
      foundFiles := aqFileSystem.FindFiles(PathWithBackSlash, pattern);
      if foundFiles <> nil then
        while foundFiles.HasNext do
        begin
          aFile := foundFiles.Next;
          result := aqString.AddListItem(result,PathWithBackSlash+aFile.name );      
        end
      else
        Log.Message('No files were found: '+PathWithBackSlash+pattern);  
    end;
    procedure testlistfiles;
    var
      s;
    begin
      s := listFiles('c:\temp\','*.xml');
      s := s+ listfiles('c:\temp\','*.zip');
      showmessage(s);
    end;
    • automateable's avatar
      automateable
      Occasional Contributor

      Thanks for your replies. 

       

      Yes, currently I'm doing the same approach. Just wondering if there's a way for SearchPattern parameter to filter multiple file types in one line.  Like ("*.jpg | *.png | *.bmp" ). Is this possible? 

      • shankar_r's avatar
        shankar_r
        Community Hero

        Unfortunately, Search only supports wild card search not reg exp. you have to use different FindFiles method to get it.