• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2025 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import sys
18
19def merge_files(input_dir, output_file):
20    if not os.path.isdir(input_dir):
21        print(f"Error: {input_dir} is not a valid directory", file=sys.stderr)
22        sys.exit(1)
23
24    with open(output_file, 'w') as out_f:
25        for filename in sorted(os.listdir(input_dir)):
26            filepath = os.path.join(input_dir, filename)
27            if os.path.isfile(filepath):
28                with open(filepath, 'r') as in_f:
29                    out_f.write(in_f.read())
30                out_f.write("\n\n")
31
32if __name__ == "__main__":
33    if len(sys.argv) != 3:
34        print(f"Usage: {sys.argv[0]} <input_dir> <output_file>", file=sys.stderr)
35        sys.exit(1)
36    merge_files(sys.argv[1], sys.argv[2])
37