Skip to content

RemoveReadOnly ​

The function RemoveReadOnly checks the file named by the parameter FileName, and if it is set with a property of ReadOnly, the ReadOnly status will be removed.

It returns a boolean result of True if the file is ReadOnly, or False if it is not. By definition, once the function has been run against a file, the result will always be True.

The FileName must include the full path.

If the file does not have ReadOnly status before the function is run against it so there is no ReadOnly status to remove, the function will still return a True value.

Please also refer to FileIsReadOnly.

Declaration: Function RemoveReadOnly(const FileName : string) : Boolean;

To try this simple example, substitute your own file names and paths, where the 1st file is not set to ReadOnly status, but the 2nd file is.

pascal
procedure ScriptEvent (var Value : variant);
 var ConfYN : boolean;
begin
  LogInfo('');
 //Display the file cyrrent status
  ConfYN := FileIsReadOnly('c:\Temp\TestFile1.txt');            //Not READONLY
 If ConfYN = true then
    LogInfo('The file TestFile1.txt is READ only')
 else
    LogInfo('The file TestFile1.txt is not READ only');
  ConfYN := FileIsReadOnly('c:\Temp\TestFile2.txt');            //Set to READONLY
 If ConfYN = true then
    LogInfo('The file TestFile2.txt is READ only')
 else
    LogInfo('The file TestFile2.txt is not READ only');

  LogInfo('');
 //Remove any READONLY property
  ConfYN := RemoveReadOnly('c:\Temp\TestFile1.txt');
 If ConfYN = true then
    LogInfo('The file TestFile1.txt READ only has been removed')
 else
    LogInfo('The file TestFile1.txt has not had READ only removed');
  ConfYN := RemoveReadOnly('c:\Temp\TestFile2.txt');
 If ConfYN = true then
    LogInfo('The file TestFile2.txt READ only has been removed')
 else
    LogInfo('The file TestFile2.txt has not had READ only removed');

   LogInfo('');
 //Display the file new status
    ConfYN := FileIsReadOnly('c:\Temp\TestFile1.txt');
 If ConfYN = true then
    LogInfo('The file TestFile1.txt is READ only')
 else
    LogInfo('The file TestFile1.txt is not READ only');
  ConfYN := FileIsReadOnly('c:\Temp\TestFile2.txt');
 If ConfYN = true then
    LogInfo('The file TestFile2.txt is READ only')
 else
    LogInfo('The file TestFile2.txt is not READ only');
   LogInfo('');

end;