You can download this code by clicking the button below.
This code is now available for download.
This function is used to get the size of a specified file in bytes.
Technology Stack : os, re, sys, json, time
Code Type : Function
Code Difficulty : Intermediate
import os
import re
import sys
import json
import time
def get_file_size(path):
"""获取文件大小
Args:
path (str): 文件路径
Returns:
int: 文件大小,单位字节
"""
if not os.path.exists(path):
return 0
return os.path.getsize(path)