Guest User

Untitled

a guest
Feb 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import os
  2.  
  3. from os import listdir
  4. from os.path import isfile, join
  5.  
  6.  
  7. def writeline(f_name,line):
  8. f = open(f_name,'a')
  9. line = line.replace("$", "")
  10. f.write(line)
  11. f.close()import os
  12.  
  13. from os import listdir
  14. from os.path import isfile, join
  15.  
  16. txt_lim = 45000000 # MB
  17. counter = 0
  18. contentseris = 0
  19.  
  20.  
  21. def writeline(f_name,line):
  22. global counter
  23. f = open(f_name,'a')
  24. #line = line.replace("$", "")
  25. counter += len(line)
  26. f.write(line)
  27. f.close()
  28.  
  29. def readNappend(src_name,f_name):
  30. global counter, contentseris
  31. try:
  32. with open(src_name, "r") as f:
  33. content = f.readlines()
  34. f.close()
  35.  
  36. for line in content:
  37. if counter >= txt_lim:
  38. counter = 0
  39. contentseris +=1
  40. f = f_name+str(contentseris)+".txt"
  41. writeline(f,line)
  42. except:
  43. print("we can not open ----"+src_name+" or write to "+f_name)
  44.  
  45. mypath = "./Cs"
  46. target = "./Codes/"
  47. onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] # one level files
  48. for root, _, files in os.walk(mypath): # or recursively open files
  49. for f in files:
  50. filename = root+"/"+f
  51. print(filename)
  52. readNappend(filename,target+"Codes")
  53.  
  54.  
  55. def readNappend(src_name,f_name):
  56. with open(src_name, "r") as f:
  57. content = f.readlines()
  58. f.close()
  59. for line in content:
  60. writeline(f_name,line)
  61.  
  62. mypath = "./src"
  63. onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
  64. for file in onlyfiles:
  65. filename = mypath+"/"+file
  66. readNappend(filename,"books.txt")
Add Comment
Please, Sign In to add comment