Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
File Attributes Strip Read Only - GetFileAttributes / SetFileAttributes
MAP
FileStripReadOnly PROCEDURE(string _filename),BOOL !True if Worked
MODULE('win32.lib')
SetFileAttributes(*CSTRING FileName,LONG NewFileAttribs),BOOL,PROC,PASCAL,DLL(1),RAW,NAME('SetFileAttributesA')
GetFileAttributes(*CSTRING FileName),LONG,PASCAL,DLL(1),RAW,NAME('GetFileAttributesA') !Returns Attribs
END
!--------------------------------------------------------
FileStripReadOnly PROCEDURE(string _filename) !,BOOL
Attrs LONG,AUTO
CFN CSTRING(261),AUTO
RetBool BOOL,AUTO
FILE_ATTRIBUTE_READONLY EQUATE( 00000001h)
INVALID_FILE_ATTRIBUTES EQUATE(0FFFFFFFFh) !(DWORD (-1))
CODE
RetBool = 0
CFN = CLIP(_filename)
Attrs = GetFileAttributes(CFN) !If the function fails, the return value is INVALID_FILE_ATTRIBUTES.
IF Attrs <> INVALID_FILE_ATTRIBUTES
IF BAND(Attrs, FILE_ATTRIBUTE_READONLY)
Attrs -= FILE_ATTRIBUTE_READONLY
IF SetFileAttributes(CFN,Attrs) !If the function succeeds, the return value is nonzero.
RetBool = True
END
END
END
RETURN RetBool
!=============================================
ExistsDirectory PROCEDURE(STRING pDirName) !,BOOL True if Directory and Not File
cFN CSTRING(261),AUTO
FA LONG,AUTO
eFILE_ATTRIBUTE_DIRECTORY EQUATE(10h) !The handle that identifies a directory.
eINVALID_FILE_ATTRIBUTES EQUATE(0FFFFFFFFh) !(-1) File or folder does not exist
CODE
cFN = CLIP(pDirName)
FA = GetFileAttributes(cFN)
RETURN CHOOSE(BAND(FA,eFILE_ATTRIBUTE_DIRECTORY) AND FA <> eINVALID_FILE_ATTRIBUTES)
!=============================================
ExistsFile PROCEDURE(STRING pFileName) !,BOOL True if File and Not Directory
cFN CSTRING(261),AUTO
FA LONG,AUTO
eFILE_ATTRIBUTE_DIRECTORY EQUATE(10h) !The handle that identifies a directory.
eINVALID_FILE_ATTRIBUTES EQUATE(0FFFFFFFFh) !(-1) File or folder does not exist
CODE
cFN = CLIP(pFileName)
FA = GetFileAttributes(cFN)
!If Not a Directory then its a file
RETURN CHOOSE(~BAND(FA,eFILE_ATTRIBUTE_DIRECTORY) AND FA <> eINVALID_FILE_ATTRIBUTES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment