There is already a program that you get with Turtles called excavate. The code of the idea you're after would be something like this
Code:
function emptyInventory()
-- Ender Chest must be in slot 1
turtle.select(1)
turtle.place()
for i = 2,16 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
turtle.dig()
end
Just read through the excavate program and find where it does an inventory empty, and drop that code in it's place.
N.B. I wrote this on the fly, so test it first.
--