1

Often there is a pattern

  1. of writing an output to temporary file(bla.txt.tmp)
  2. deleting the original (rm bla.txt)
  3. renaming a new one(bla.txt.tmp -> bla.txt)

Is there any utility function in std::filesystem to do this or I need to do steps one by one using rename and remove.

NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277

1 Answers1

4

No. There is no such utility function in the standard library. Each step can be done with std::filesystem though and you can write such utility function yourself.

std::filesystem::rename does perform both steps 2. and 3. in one call, but creating the new file must be done separately.

eerorika
  • 232,697
  • 12
  • 197
  • 326