Yes the bank can foreclose even if the loan is under review for modification. But communication is the key...if you have received a notice of trustee sale you need to contact the person you have been working with on the loan modification to see if the foreclosure is proceeding, if not...get it in writing!
Also as far as when you have to leave the property...look at the Notice of Trustee's Sale document...in there will be the date of the sale...that is when the property will revert back to the bank. Typically after it goes back to the bank they will begin the eviction process and they may make arrangements to exchange cash for keys (depending on the lender). But you will have notice....you will not literally be thrown out into the street. Again, communication is key...respond to calls, posts to the property and mail.
Good luck...hopefully your modification will go thru.