How to let code find the file size and how to let user input segment size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pohweihao
    New Member
    • Jul 2014
    • 1

    How to let code find the file size and how to let user input segment size

    Code:
    f = open("centaur_1.mpg","rb")
    #create a for loop and split file into 20 parts
    buffer=f.read()  # readinto a large buffer to check its size
    #f.close() #close the file
    filesize=len(buffer)
    print filesize
    splitsize=int(filesize/segmentsize)
    f.seek(0)  # reset to beginning of file
    #smallfbuf=[]
    for i in range(splitsize+1):
        filename="part"+str(i)+".mpg"
        f2= open(filename,"wb")
        buffer2 = f.read(splitsize)
        f2.write(buffer2)
        f2.close()
    f.close()

    from the above codes, how do i get the filesize and the user to input segmentsize
    Last edited by bvdet; Jul 3 '14, 01:10 PM. Reason: Ad code tgs
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    It looks like you can import os and then use the getsize() function to see the filesize:

    [code=python]
    import os
    size = os.path.getsize ('centaur_1.mpg ')
    print size
    [/code]

    So I got that from Googling "python get file size" and I would Google "python get user input" to allow the user to input the segment size.

    Good luck!

    Comment

    Working...