Implement the file conversion script

This commit is contained in:
TropiiDev 2025-01-05 00:52:16 -05:00
commit 39172484e7
9 changed files with 119 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/
.venv/

8
.idea/.gitignore generated vendored Normal file
View File

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

10
.idea/FileConverter.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 (FileConverter)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 (FileConverter)" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FileConverter.iml" filepath="$PROJECT_DIR$/.idea/FileConverter.iml" />
</modules>
</component>
</project>

66
main.py Normal file
View File

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

1
text.txt Normal file
View File

@ -0,0 +1 @@
this is a test txt file