Basically just delete all your wordpress files (backup things like plugins, themes, smilies etc) and then re-upload all the wordpress files onto your server. this will not delet any posts, comments or pages as these are all stored on your database.
In order to stop this happening again you need to change the file permissions on your files to something that other people (apart from wordpress) can’t write to. I a no expert on this; prehaps someone else can recommend a file permission.