/ Published in: Python
Expand |
Embed | Plain Text
def file_size_mb(filePath): return float(os.path.getsize(filePath)) / (1024 * 1024)
Comments
Subscribe to comments
You need to login to post a comment.
def file_size_mb(filePath): return float(os.path.getsize(filePath)) / (1024 * 1024)
Subscribe to comments
You need to login to post a comment.
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:
def filesizemb(filepath): if os.path.exists(filepath): return (float(os.path.getsize(filepath)))/1024 * 1024 return -1
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.
Thanks.