I would advise strongly against executing a file as a way to test whether it's executable. If you don't know what a file is, don't just run it! This is a security and general damage nightmare. This is analogous to testing whether a vial of clear liquid is poison by drinking it.
Step 1: read it's metadata via stat
On posix (linux, mac, bsd), use fs.stat then examine the mode field to check for the various permutations executable.
Step 2: read the beginning of the file data and guess the type
You can run the file utility on it, which will use a database of magic numbers and other heuristics to guess the file type.
Windows
In terms of platform independent, AFAIK this functionality just isn't similar enough on Windows for there to be a reliable Windows equivalent of the above posix-oriented techniques. Windows filesystems and filetypes are different, so I think if you want this to really work, you'll need a separate implementation to handle windows properly (and someone other than me to suggest how to implement it on windows).