1

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

joe
  • 463
  • 4
  • 17

1 Answers1

2

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
coolreader18
  • 701
  • 9
  • 14