How to determine if a file is executable?

前端 未结 6 1380
温柔的废话
温柔的废话 2020-12-21 01:36

I\'m writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as poss

6条回答
  •  借酒劲吻你
    2020-12-21 02:06

    In Windows there is no real notion of "executable", like the specific permission that exists in *NIX systems.

    You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.Start) has many advantages - it leaves the power of association to the user, as in letting the user pick the correct way to run the various file types.

    The second option is to mimic the Windows file association process, by having a dictionary from an extension to the command that can run the file, and falling back to checking the first line of the file if needed. This has the advantage of you having the power of setting the associations, but it also requires constant modifications and maintenance on your side, in addition to losing the flexibility on the user side - which may be a good thing or a bad thing.

提交回复
热议问题