Skip to content

Instantly share code, notes, and snippets.

@CynicRus
Last active February 10, 2024 16:56
Show Gist options
  • Save CynicRus/0e51a2dcaf78c3a1ee4c6412836a47a5 to your computer and use it in GitHub Desktop.
Save CynicRus/0e51a2dcaf78c3a1ee4c6412836a47a5 to your computer and use it in GitHub Desktop.
The script to output files in which the substring is not found
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