Last active
February 10, 2024 16:56
-
-
Save CynicRus/0e51a2dcaf78c3a1ee4c6412836a47a5 to your computer and use it in GitHub Desktop.
The script to output files in which the substring is not found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import io | |
import argparse | |
def unfind_substr(directory, word): | |
files = os.listdir(directory) | |
finalFiles = [] | |
for file in files: | |
filename = os.path.join(directory, file) | |
if os.path.isfile(filename): | |
with io.open(filename) as f: | |
found = False | |
for line in f: | |
if word in line: | |
found = not found | |
break | |
if not found: | |
finalFiles += [file] | |
return finalFiles | |
parser = argparse.ArgumentParser(description='The script to output files in which the substring is not found') | |
parser.add_argument("-d", "--dir", type=str,required=True, help='Input dir for searching') | |
parser.add_argument('-s',"--search", type=str,required=True, help='Searched substring in dir') | |
args = parser.parse_args() | |
if os.path.isdir(args.dir): | |
result = unfind_substr(args.dir, args.search) | |
for l in result: | |
print(l) | |
print("done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment