From 39172484e73443d06f476f5a3a24f64396cc8b8e Mon Sep 17 00:00:00 2001 From: TropiiDev Date: Sun, 5 Jan 2025 00:52:16 -0500 Subject: [PATCH] Implement the file conversion script --- .gitignore | 2 + .idea/.gitignore | 8 +++ .idea/FileConverter.iml | 10 +++ .idea/inspectionProfiles/Project_Default.xml | 12 ++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ main.py | 66 +++++++++++++++++++ text.txt | 1 + 9 files changed, 119 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/FileConverter.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 main.py create mode 100644 text.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e8ecb4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.venv/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/FileConverter.iml b/.idea/FileConverter.iml new file mode 100644 index 0000000..f1c3127 --- /dev/null +++ b/.idea/FileConverter.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..f281ec3 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c556b6c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a49bf8a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..ce0b9fe --- /dev/null +++ b/main.py @@ -0,0 +1,66 @@ +import getopt, sys +import json +import os + +# Remove 1st argument from the +# list of command line arguments +argumentList = sys.argv[1:] + +# Options +options = "hmo:" + +# Long options +long_options = ["Help", "File", "Name"] + +try: + # Parsing argument + arguments, values = getopt.getopt(argumentList, options, long_options) + + # checking each argument + for currentArgument, currentValue in arguments: + + if currentArgument in ("-h", "--Help"): + print(""" + Displaying Help! + + This is a simple Python Script for quickly renaming files. + Sure you could do it in your file manager. Is it easier? Absolutely. + Why use this? Who knows, but you are. + + Options: + --File - Select a valid file + --Name - the desired name for the file + + Example: + python3 main.py --File text.txt --Name text2.txt + """) + + elif currentArgument in ("-f", "--File"): + print("Displaying file_name:", sys.argv[2]) + + correct = input("Is this the file you want to select?: (y/n) ") + + if correct == "y": + is_file = os.path.isfile(sys.argv[2]) + + if is_file is False: + print("That is not a file.. Try again") + break + + new_name = sys.argv[4] + + if new_name is None: + print("Please add the `--Name` argument.") + break + + os.rename(sys.argv[2], new_name) + + print("The file renaming has been complete. Thank you!") + + + elif currentArgument in ("-n", "--Name"): + print("Please specify the file first") + +except getopt.error as err: + # output error, and return with an error code + print (str(err)) \ No newline at end of file diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..5a65a72 --- /dev/null +++ b/text.txt @@ -0,0 +1 @@ +this is a test txt file \ No newline at end of file