usr_w can be AND'd (see and operator (bitwise)) with the filemode retrieved by the built-in procedure getfilemode to determine whether the owner of a file or directory/folder has permission to write to the file or directory/folder.


For example the simple program below asks for a filename and then displays the file permissions for the owner of the file.

   program OwnerPermissions(input, output);
      s : filename;
      mode : integer;
      isdir : boolean;
      write('Enter filename:');
      s := fexpand(s);
      getfilemode(s, mode);
      isdir := (mode and dir_bit) <> 0;
      if isdir then
         writeln(s, ' is a directory')
         writeln(s, ' is not a directory');
      write('Owner permissions :');
      if (mode and usr_r) <> 0 then
         write(' Read');
      if (mode and usr_w) <> 0 then
         write(' Write');
      if (mode and usr_x) <> 0 then
         if isdir then
            write(' Search')
            write(' Execute');


Operating Systems: All
Standard Pascal: No