Reading file attributes (check if a file is read only)

Hi all,

Just a small question (I hope). I would like to be able to check from NAV if a certain file is read only or not.

I tried to fix something with a file variable and with the file table. But I can’t figure out to read the attributes of the file.

Any suggestions?

Hi Marco,

not sure if this really works but we often use the rename function to check if a file is already completly written. As in

if rename(filename,filename) then

fileispresent := ok;

maybe you can use this also for your problem?



Ok, got it…

This is how you do it:

You need the following variables:

  • FileSystemObject: Automation - ‘Microsoft Scripting Runtime’.FileSystemObject
  • MyFile: Automation - ‘Microsoft Scripting Runtime’.File
  • MyAttributes: Integer

IsReadOnly(FileName: Text(250)):Boolean
IF ISCLEAR(FileSystemObject) THEN
MyFile := FileSystemObject.GetFile(Filename);
MyAttributes := MyFile.Attributes;

IF (MyAttributes MOD 2 <> 0) THEN
EXIT(TRUE) //Readonly
EXIT(FALSE); //Read-write

I found the info here

Hi Jan,

Thanks for the input but I wanted to show the readonly attribute in a form. So creating an error was not an option. But I think I found it. :slight_smile: