Problem:
When running a program and calling the CBL_DELETE_FILE-routine, files being write-protected are not deleted. How to change the file attributes for those files with a CBL-routine without using a DOS box?
Resolution:
Windows API functions can be used to unset the read-only attribute of files.
copy Windows.cpy.
program-id. main.
special-names.
call-convention 66 is WinApi.
working-storage section.
01 Attrib DWORD.
01 ReadOnlyOff-Mask DWORD.
01 B-RetVal BOOL.
01 RetVal PIC X(2) COMP-5.
call WinApi GetFileAttributes using z"MyFile"
returning Attrib
move -1 to ReadOnlyOff-Mask
subtract FILE-ATTRIBUTE-READONLY from ReadOnlyOff-Mask
call "CBL_AND" using ReadOnlyOff-Mask Attrib value 2 size 4
call WinApi SetFileAttributes using z"MyFile"
value Attrib
returning B-RetVal
if B-RetVal = 0
display "unable to set attributes"
else
call "CBL_DELETE_FILE" using z"MyFile"
returning RetVal
end-if
goback.
