joe
joe

Reputation: 533

How do I check if a file is an executable in nim?

How do I check if a file is an executable on Linux using Nim? Thanks in advance.

Upvotes: 1

Views: 264

Answers (1)

coolreader18
coolreader18

Reputation: 719

You can use getFilePermissions and check if a certain FilePermission is in the set it returns.

import os

let isExecutable = fpOthersExec in getFilePermissions "./filename"

You'd probably want to check if all three different Exec variants are in it:

import os

proc isExecutable(filename: string): bool =
  let filePermissions = getFilePermissions filename
  fpUserExec in filePermissions and
    fpGroupExec in filePermissions and
      fpOthersExec in filePermissions

Upvotes: 2

Related Questions