aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/FileRenamer.h
blob: 91f74f090321045e3aaa48dcce05f7d89a9dc5f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include <string>
#include <base/types.h>

namespace DB
{

/**
  * The FileRenamer class provides functionality for renaming files based on given pattern with placeholders
  * The supported placeholders are:
  *   %a - Full original file name ("sample.csv")
  *   %f - Original filename without extension ("sample")
  *   %e - Original file extension with dot (".csv")
  *   %t - Timestamp (in microseconds)
  *   %% - Percentage sign ("%")
  *
  * Example:
  *   Pattern             - "processed_%f_%t%e"
  *   Original filename   - "sample.csv"
  *   New filename        - "processed_sample_1683405960646224.csv"
  */
class FileRenamer
{
public:
    FileRenamer();

    FileRenamer(const String & renaming_rule);

    String generateNewFilename(const String & filename) const;

    bool isEmpty() const;

    static bool validateRenamingRule(const String & rule, bool throw_on_error = false);

private:
    String rule;
};

} // DB