Guest User

Untitled

a guest
Dec 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. # All perpose file converter
  2. # Bobby Clarke 2012
  3. # GNU General Public License 3.0
  4.  
  5. import easygui
  6. import sys
  7. import os
  8.  
  9. def removeExtention(filename):
  10. newname = ""
  11.  
  12. for char in filename:
  13. if char == ".":
  14. break
  15.  
  16. else:
  17. newname += char
  18.  
  19. return newname
  20.  
  21. def get_dir(files = True):
  22. """Get the directory the program is in, have True as a parameter to get a list of the files within said directory"""
  23.  
  24. selfdir = os.path.dirname(sys.argv[0])
  25.  
  26. if files:
  27. return os.listdir(selfdir)
  28. else:
  29. return selfdir
  30.  
  31. def convert(filename, newExtention):
  32. file = open(filename , "rb")
  33. writefile = open(removeExtention(filename) + newExtention, "wb")
  34.  
  35. writefile.write(file.read())
  36.  
  37. file.close()
  38. writefile.close()
  39.  
  40. def main():
  41. question = "Which file do you wish to covert?"
  42. title = "Universal File Converter"
  43. newExtention = ""
  44.  
  45. filename = easygui.choicebox(question, title, get_dir())
  46.  
  47. if filename is None:
  48. sys.exit()
  49.  
  50. while not newExtention:
  51. newExtention = easygui.enterbox("New file extention (eg .png, .txt)")
  52.  
  53. if newExtention is None:
  54. sys.exit()
  55.  
  56. convert(filename, newExtention)
  57.  
  58. if __name__ == "__main__":
  59. main()
Add Comment
Please, Sign In to add comment