File size: 651 Bytes
ba7d855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python

import os
from pathlib import Path

def rename_txt_to_tags(target_dir='.'):
    for root, dirs, files in os.walk(target_dir):
        for file in files:
            if file.endswith('.txt'):
                txt_file = Path(root) / file
                tags_file = txt_file.with_suffix('.tags')
                os.rename(txt_file, tags_file)
                print(f"Renamed {txt_file} to {tags_file}")

if __name__ == '__main__':
    target_directory = input('Enter the target directory (leave blank for current directory): ')
    if not target_directory:
        target_directory = '.'
    rename_txt_to_tags(target_directory)