quote from the wiki:
get_disk_size
get_free_disk_space
Returns values in KB. You can build scripts now which stop when specific disk limit exceeded. For easier calculation divide by 1024 to return value in MB.
Syntax: x=get_disk_size, x=get_free_disk_space
Example, to print the space left in megabytes, print get_free_disk_space/1024 (this, among some others, is one of those commands that acts as its own variable)
get_jpg_count
get_raw_count
Syntax: x=get_jpg_count, x=get_raw_count (acts as its own variable which may be assigned to other variables)
Returns the calculated value of how many JPG or RAW shot space is left available on the SD card. (JPG value is approximated and taken from an average of file-sizes, using Canon's own algorithm, the same as shots remaining left in your EVF/LCD display.) Use this command to detect when not enough space is remaining for your required script task to either end the script or shut_down the camera.
with these commands you should be able to do the stuff you wanna

edit: reyalp beat me to it, but i explained further
