locatefolder?


    Oct 19 2014 | 8:50 am
    Hello everybody,
    locatefile_extended() works well to locate files in the search path, but I need to locate a *folder* in the search path. Does anybody know how to do that? Without really knowing what's inside the folder...
    Thanks, Daniele

    • Oct 19 2014 | 7:19 pm
      Ciao Daniele,
      hope you are well...
      If I understand you correctly you want to locate a folder in the search path. I assume you know the name of that folder and obviously you know the search path.
      Basically the function you need to start the process is:
      path_frompathname()
      
      That will return a path ID that you will feed to:
      path_openfolder()
      
      This function will return a "folder state" structure that you should save and use to enumerate all the folders in the directory (the search path) with:
      path_foldernextfile()
      
      That will provide you with the name of each folder in the directory. You will need to compare every name with the specific folder's name you are looking for.
      Finally you gotta call:
      path_closefolder()
      
      in order to complete the iteration.
      I recommend you check out the ext_path.h file and the folder.c example in the Max/MSP SDK 6.1.4. All the information you really need is there.
      Hope this helps.
      - Luigi
    • Oct 19 2014 | 8:31 pm
      Hi Luigi,
      thanks a lot for replying. I'm not sure I got your hints – I mean, I'm not sure that's what I need, or maybe I just can't see it.
      I need the user to enter "foo", and if "foo" is somewhere inside the search path, the folder "/my/path/to/foo" will be returned. The fact is that path_frompathname() on "foo" simply returns 0, and that's all. If "foo" were a file (say "foo.bar"), even if path_frompathname() is 0 I'd easily call locatefile_extended() to get path, name and type. However, since "foo" is a folder, I really don't know how to do that. I'm surely missing some important point in your answer... Can you maybe clarify a little?
      Also, I'm pretty sure I don't know how to retrieve the whole search path (I just know how to retrieve the default one via path_getdefault()); if I knew that, I might traverse it entirely to look for the folder (although I was really hoping in an undocumented but perfectly working locatefolder() function ;-)
      Thanks again, Daniele
    • Oct 20 2014 | 7:36 am
      Sorry Daniele... my bad. I got confused by the way your question is worded. You can actually use locatefile_extended() to locate folders as well.
      void locatefolder(t_symbol *foldername)
      {
          char name[MAX_FILENAME_CHARS];
          short path;
          t_fourcc type;
          
          strncpy_zero(name, foldername->s_name, MAX_FILENAME_CHARS);
          if (locatefile_extended(name, &path, &type, NULL, 0)) {
              error("folder %s not found", name);
          } else {
              post("folder %s, path %d", name, path);
          }
      }
      
      If you need to convert it to a fully qualified path:
      char pathname[MAX_PATH_CHARS];
      short err;
      
      err = path_topathname(path, name, pathname);
      
      Let me know if everything is clear now.
      - Luigi
    • Oct 20 2014 | 8:24 am
      Oh gosh, I was really under the impression that the locatefile function only worked for files... And I thought I even tested that. I must have gotten confused; indeed as you say they work great for folders as well.
      Thanks a lot, Luigi, and sorry for the trivial question. Hope you're fine!
      Daniele