Gif 2 TXT

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import os, base64

class MyApp:
def __init__(self):
print('===> file2txt v1.0 <===\n')
self.doMenu()
def doMenu(self):
while True:
choice = input('1. Select directory\n'
'2. Show active directory\n'
'3. Choose file\n'
'4. Show selected file name\n'
'5. Convert file\n'
'6. Advanced options\n'
'7. Quit\n'
'=> ')
try: choice = int(choice)
except: print('Wrong value')
else:
if choice is 1:
try:
os.chdir(input('Enter new directory path\n=> '))
except: print('Error, try again')
elif choice is 2: print(os.getcwd())
elif choice is 3: self.chooseFile()
elif choice is 4:
try: print(self.fileName)
except: print('File non chosen already')
elif choice is 5:
try: self.fileName
except: print('Choose a file name before, dude')
else: self.convert()
elif choice is 6: self.advancedMenu()
elif choice is 7: quit()
def chooseFile(self):
temp = input('Enter file name \n=> ')
if os.path.isfile(temp):
print('File found!\n')
self.fileName = temp
else:
print('File not found...\n')
def convert(self):
if os.path.splitext(self.fileName)[1] == '.txt':
# =====> IL FILE E' UN FILE .TXT <=====
print('I guess you want to decode .txt back to its original extensio
n\n')
self.newExtension = input('Enter new file extension\n => ')
if self.newExtension[0] is not '.':
self.newExtension = '.' + self.newExtension
print('Added a point to your extension\n')
self.newFileName = os.path.splitext(self.fileName)[0] + self.newExte
nsion
self.checkName()
print('Converting your file...\n')
base64.decode(open(self.fileName, 'rb'), open(self.newFileName, 'wb'
))
print('Done')
else:
# =====> IL FILE E' UN FILE GENERICO <=====
print('File will be converted to .txt\n')
self.newExtension = '.txt'
self.newFileName = os.path.splitext(self.fileName)[0] + self.newExte
nsion
self.checkName()
print('Converting your file...\n')
base64.encode(open(self.fileName, 'rb'), open(self.newFileName, 'wb'
))
print('Done')
def checkName (self):
count = 1
while os.path.isfile(self.newFileName):
temp = os.path.splitext(self.newFileName)[0] + '(' + str(count) + ')
' + os.path.splitext(self.newFileName)[1]
if not os.path.isfile(temp):
self.newFileName = temp
else:
count += 1
def advancedMenu(self):
while True:
choice = input('1. Split encoded file in more than one .txt file\n'
'2. Encode/decode all files in selected directory\n'
'3. \n'
'4. Back to main menu\n'
'=> ')
myApp = MyApp()

You might also like