Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # Imports
  2. import os
  3.  
  4. # Constants
  5. FILES_IN_DIR = os.listdir()
  6.  
  7. # Functions
  8. def getInput():
  9. source = ""
  10. print("Options: ")
  11. for i in FILES_IN_DIR:
  12. print(i)
  13. print('\n')
  14. while source not in FILES_IN_DIR:
  15. source = input("Please enter the name of the source file: ")
  16. return source
  17.  
  18. def findExtension(source):
  19. return source.find('.')
  20.  
  21. def getSourceInfo(source):
  22. f=open(source, "r")
  23. sourceInfo = f.read()
  24. f.close()
  25. srcInfo = [source[:findExtension(source)-1:-1], sourceInfo]
  26. return srcInfo
  27.  
  28. def createNewFile(srcInfo):
  29. newFileName = input("Please enter the name of the new file: ")
  30. f=open((newFileName+srcInfo[0][::-1]),"w")
  31. f.write(srcInfo[1])
  32. f.close()
  33.  
  34. def main():
  35. createNewFile(getSourceInfo(getInput()))
  36.  
  37. # Running the Program
  38. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement