advanced code snippet search
iloveitaly on 05/31/10
file path python size mb megabyte
def file_size_mb(filePath): return float(os.path.getsize(filePath)) / (1024 * 1024)
Report this snippet
If file does not exist, will raise an exception, wouldn't be more friendly to check if file exists first.
Here is my code based on yours:
return (float(os.path.getsize(filepath)))/1024 * 1024
Great addition. This snippit was being used within the context of code that was already checking for file existence, so I didn't think to add it to the function itself.
You need to login to post a comment.