Create A List Of File Names

Synopsis

Create a list of numbered file names.

Results

Output:

output_0.png
output_10.png
output_20.png
output_30.png
output_40.png
output_50.png
output_60.png
output_70.png
output_80.png
output_90.png
output_100.png
output_110.png
output_120.png
output_130.png
output_140.png
output_150.png

***************

output_0000.png
output_0010.png
output_0020.png
output_0030.png
output_0040.png
output_0050.png
output_0060.png
output_0070.png
output_0080.png
output_0090.png
output_0100.png
output_0110.png
output_0120.png
output_0130.png
output_0140.png
output_0150.png

Code

C++

#include "itkNumericSeriesFileNames.h"

int
main(int, char *[])
{
  itk::NumericSeriesFileNames::Pointer numericSeriesFileNames = itk::NumericSeriesFileNames::New();
  numericSeriesFileNames->SetStartIndex(0);
  numericSeriesFileNames->SetEndIndex(150);
  numericSeriesFileNames->SetIncrementIndex(10);
  numericSeriesFileNames->SetSeriesFormat("output_%d.png");

  std::vector<std::string> fileNames = numericSeriesFileNames->GetFileNames();

  for (const auto & fileName : fileNames)
  {
    std::cout << fileName << std::endl;
  }

  std::cout << std::endl;
  std::cout << "***************" << std::endl;
  std::cout << std::endl;

  numericSeriesFileNames->SetSeriesFormat("output_%04d.png");

  fileNames = numericSeriesFileNames->GetFileNames();

  for (const auto & fileName : fileNames)
  {
    std::cout << fileName << std::endl;
  }

  return EXIT_SUCCESS;
}

Classes demonstrated

class NumericSeriesFileNames : public itk::Object

Generate an ordered sequence of filenames.

This class generate an ordered sequence of files whose filenames contain a single unique, non-negative, integral value (e.g. test.1.png, test2.png, foo.3, etc.).

The file name is created from a sprintf-style series format which should contain an integer format string like “%d”. Bad formats will cause the series reader to throw an exception.

Warning: returned filenames (which may be full or relative paths) are not checked against any system-imposed path-length limit, because of difficulties finding a portable method to do so.

ITK Sphinx Examples:

See itk::NumericSeriesFileNames for additional documentation.