-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMassExtensionChanger.py
More file actions
142 lines (109 loc) · 4.72 KB
/
MassExtensionChanger.py
File metadata and controls
142 lines (109 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Mass Extension Changer
# Coded by Zane ZenOokami Blalock
# http://EssenceOfZen.org/
# This program essentially takes in your entered directory and changes any specified extension
# with another extension specified.
# Feel free to fork this project and make what you will with it, we simply ask that you give credit, and link back
# to our source location at our site (EssenceOfZen.org) and our GitHub. Thank you <3
# TODO: Add Menu
# TODO: Add more user-proofing
# TODO: Create a GUI?
# TODO: Create more console communication to know what's going on
import os
from tkinter import filedialog
import EssencePython
from tkinter import *
# Global Variables ===========================
VERSION = "1.9.00" # A variable to call for showing update once menu is made
DIRECTORY = "" # used for the directory url location
DIRECTORY_ITEMS = [] # This is an array to house the items inside the directory
#ROOT = Tk()
# Functions ===========================
def changeDirectory(): # Function allows to change the Directory
global DIRECTORY
# We ask for the directory
directory = "" # Create an empty string for the directory location
print("(You can copy the url from window's explorer directory bar)")
user_input = input("Please enter directory location: ") # Have the user input the directory - they can copy and paste from window's explorer
for item in user_input: # If the directory uses backslash (like from window's syntax), change them to forward slash for Python's syntax
if item == '\\':
item = '/'
directory += item
length = len(directory) # We grab the length of the directory, and use -1 to get the index of the last character
if directory[length-1] != "/": # If there isn't a / at the end of the directory, add one.
directory += "/"
print("Added '/' to the url!")
print("")
DIRECTORY = directory # We set the global variable
print("Directory Changed!")
print("")
def printDirectoryItems(directory): # Prints the items found in the Directory **REDO THIS CODE LATER SINCE UPDATE
global DIRECTORY_ITEMS
directory_items = os.listdir(directory) # Sets a variable to be an array of items
print("Printing Files and Folders: ")
for item in directory_items:
print(item)
DIRECTORY_ITEMS = directory_items
def changeExtension(selection, target):
global DIRECTORY
global DIRECTORY_ITEMS
for file in DIRECTORY_ITEMS:
current_file = os.path.join(DIRECTORY, file) # We add the folder's url to the file name to create file's url
if selection in current_file:
print(current_file)
new_name = current_file.replace(selection, target)
output = os.rename(current_file, new_name)
else:
print("Selection was not found...")
print("")
def updateDirectory(): # Updates the Directory with any changes that you've made on the files.
global DIRECTORY
global DIRECTORY_ITEMS
DIRECTORY_ITEMS = os.listdir(DIRECTORY)
#def directoryDialog(root):
# root.fileDirectory = filedialog.askdirectory()
# return root.fileDirectory
def menu(): # TODO: Finish this function
pass
# Tkinter functions ================================================================================================
def initializeGUI():
pass
# Main Function ====================================================================================================
def main():
EssencePython.EoZ_Logo() # Calls our Console logo
# Pull down our global variables for the main function
global DIRECTORY
global DIRECTORY_ITEMS
global ROOT
# Start the program by getting the directory
# Later create a menu
main_switch = 1
while main_switch == 1:
changeDirectory() # Deprecated
#DIRECTORY = directoryDialog(ROOT)
#print(DIRECTORY)
print()
printDirectoryItems(DIRECTORY)
print()
print("Please enter your target extension to change")
selection = input("please enter extension such as .txt or .html: ")
print()
print("Please enter what extension you wanted to switch it to")
target = input("please enter extension different than before: ")
print()
changeExtension(selection, target)
print()
updateDirectory()
answer = input("Are you finished?: ").lower()
continue_loop = 1
while continue_loop == 1:
if answer == "yes" or answer == "y":
continue_loop = 0
main_switch = 0
elif answer == "no" or answer == "n":
continue_loop = 0
main_switch = 1
else:
print("Answer is invalid, try again please.")
continue_loop = 1
main()