From 2ce4fdb3575f39afc238648219657d522ca6a5c0 Mon Sep 17 00:00:00 2001 From: Aditya Jetely Date: Sun, 16 Aug 2020 12:58:15 +0530 Subject: [PATCH 1/3] Added word_detector to System Automation Scripts --- System-Automation-Scripts/word_detector.py | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 System-Automation-Scripts/word_detector.py diff --git a/System-Automation-Scripts/word_detector.py b/System-Automation-Scripts/word_detector.py new file mode 100644 index 00000000..77d5317c --- /dev/null +++ b/System-Automation-Scripts/word_detector.py @@ -0,0 +1,56 @@ +"""[This script is used to detect whether a given word is present in a list of files. + All the files which contain the specified word gets stored in a seperate folder. + +It takes two inputs - +1.Path of the directory which contains the files. + +[Sample path - "C:/Users//Desktop//"] + +2.Word that you want to detect in these files. +[Sample word - "awesome"] + +] +""" + +import os +import shutil + +# Inputs +directory_path = input("Enter the absolute path of the folder: ") +detect_this = input("Enter the word you want to detect in the files: ") + +# Condition to omit creation of the folder if it already exists. +if f"Flagged_{detect_this}" not in os.listdir(directory_path): + os.mkdir(f"Flagged_{detect_this}") + +# Creates a list of all the files/directories in the provided path +files = os.listdir(directory_path) + +# To omit adding the python script and the folder in the list of files. +files.remove(f"Flagged_{detect_this}") +files.remove("detector.py") + +# List to collect the files which contains the target word +flagged_files = [] + +# Logic to loop over the files and check for the presence of the target word in them and adding them to the flagged_files list. +for file in files: + with open(file, "r") as f: + if detect_this.lower() in f.read().lower(): + flagged_files.append(file) + + +# Looping over the flagged files and moving them to a seperate folder +for file in flagged_files: + shutil.move(directory_path+file, directory_path + + "Flagged_"+detect_this) + +# To make the output look organised +print( + f"The script was successfull in detecting {detect_this} in the list of files") +print(" ") +print("Summary of the detection: ") +print(f"Total Files: {len(files)}") +print(f"Files with the target word: {len(flagged_files)}") +print(" ") +print("Thanks for using this script..........") From 66892b681c5f2bba4907908ac47433a55804dcfe Mon Sep 17 00:00:00 2001 From: Aditya Jetely Date: Tue, 18 Aug 2020 08:09:22 +0530 Subject: [PATCH 2/3] Added Readme and created a separate folder --- System-Automation-Scripts/Word detector/README.md | 14 ++++++++++++++ .../{ => Word detector}/word_detector.py | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 System-Automation-Scripts/Word detector/README.md rename System-Automation-Scripts/{ => Word detector}/word_detector.py (78%) diff --git a/System-Automation-Scripts/Word detector/README.md b/System-Automation-Scripts/Word detector/README.md new file mode 100644 index 00000000..2a01dd00 --- /dev/null +++ b/System-Automation-Scripts/Word detector/README.md @@ -0,0 +1,14 @@ +### Word Detector + +#### This script is used to detect whether a given word is present in a list of files.All the files which contain the specified word gets stored in a seperate folder. + +#### It takes two inputs - + 1.Path of the directory which contains the files. + [Sample path - "C:/Users//Desktop//"] + + 2.Word that you want to detect in these files. + [Sample word - "awesome"] + +#### The output it produces - + + A seperate folder in the current directory which contains the target files(files that contain the input word). \ No newline at end of file diff --git a/System-Automation-Scripts/word_detector.py b/System-Automation-Scripts/Word detector/word_detector.py similarity index 78% rename from System-Automation-Scripts/word_detector.py rename to System-Automation-Scripts/Word detector/word_detector.py index 77d5317c..4881c109 100644 --- a/System-Automation-Scripts/word_detector.py +++ b/System-Automation-Scripts/Word detector/word_detector.py @@ -1,17 +1,3 @@ -"""[This script is used to detect whether a given word is present in a list of files. - All the files which contain the specified word gets stored in a seperate folder. - -It takes two inputs - -1.Path of the directory which contains the files. - -[Sample path - "C:/Users//Desktop//"] - -2.Word that you want to detect in these files. -[Sample word - "awesome"] - -] -""" - import os import shutil From 26ba78c5207f63688649c64554056e8dc588a65c Mon Sep 17 00:00:00 2001 From: Aditya Jetely Date: Tue, 18 Aug 2020 08:16:42 +0530 Subject: [PATCH 3/3] Update README.md --- System-Automation-Scripts/Word detector/README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/System-Automation-Scripts/Word detector/README.md b/System-Automation-Scripts/Word detector/README.md index 2a01dd00..a1132817 100644 --- a/System-Automation-Scripts/Word detector/README.md +++ b/System-Automation-Scripts/Word detector/README.md @@ -3,12 +3,15 @@ #### This script is used to detect whether a given word is present in a list of files.All the files which contain the specified word gets stored in a seperate folder. #### It takes two inputs - - 1.Path of the directory which contains the files. - [Sample path - "C:/Users//Desktop//"] + +1.Path of the directory which contains the files. + +[Sample path - "C:/Users//Desktop//"] + +2.Word that you want to detect in these files. - 2.Word that you want to detect in these files. - [Sample word - "awesome"] +[Sample word - "awesome"] #### The output it produces - - A seperate folder in the current directory which contains the target files(files that contain the input word). \ No newline at end of file +A seperate folder in the current directory which contains the target files(files that contain the input word).