k4d3 commited on
Commit
1b6e1a9
1 Parent(s): 7e3d05b

remove_tag

Browse files

Signed-off-by: Balazs Horvath <acsipont@gmail.com>

Files changed (1) hide show
  1. remove_tag +33 -0
remove_tag ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import pathlib
5
+ import re
6
+
7
+ def remove_word_from_file(file_path, word):
8
+ with open(file_path, 'r', encoding='utf-8') as file:
9
+ content = file.read()
10
+
11
+ # Remove the word with the comma and space if there is one after it
12
+ pattern = re.compile(r'\b' + re.escape(word) + r',?\s?')
13
+ new_content = pattern.sub('', content)
14
+
15
+ with open(file_path, 'w', encoding='utf-8') as file:
16
+ file.write(new_content)
17
+
18
+ def remove_word_from_directory(directory, word):
19
+ path = pathlib.Path(directory)
20
+ for txt_file in path.rglob('*.txt'):
21
+ remove_word_from_file(txt_file, word)
22
+
23
+ if __name__ == "__main__":
24
+ import sys
25
+ if len(sys.argv) != 3:
26
+ print("Usage: python script.py <directory> <word>")
27
+ sys.exit(1)
28
+
29
+ target_directory = sys.argv[1]
30
+ target_word = sys.argv[2]
31
+
32
+ remove_word_from_directory(target_directory, target_word)
33
+