FileConverter/main.py

66 lines
1.8 KiB
Python

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))