C++ multiple files with common name beginning -


Is there a way to open files, whose names and zodiac have the same name without specifying? They should be open after one, not all at once. For example, I have the files: Definitely 1 23.txt, certainstr_5329764.txt, certainstr_1323852.txt.

Or, maybe it can be done more easily in any other language? Thank you.

C ++ does not define a standard way of listing files in that way.

The best cross-platform approach is to use a library such as modules. I do not think there is wildcard search in the Promotion: filesystem , you have to filter yourself, but it is not difficult.

You can use regular expressions, like the answer in another (this is the right solution) This file extension ( i- & gt; path (). Extension () ) and the file name can be enough to start "certainstr _" ( boost: :). Start_with or std :: string :: substr ). If you choose the C ++ 11 Standard Regex Library, make sure that a libstdc ++

  • P>

    You can try anything (windows):

      std :: system ("dir / b specificstr _ * .txt> list.txt");  

    or (unix):

      std :: system ("ls -m1 specificstr _ * .txt> list.txt");  

    list.txt parsing the output file (of course this is a hack). Anyway, depending on your needs, Python-based (or script-based) solutions can be simpler (see also):

      [glob.glob ( 'Certainstr _ * .txt')] [3]  

    or also:

      files = [f for os.listdir ('.') If  

    is equal to

    Comments