Code archives/File Utilities/File attributes

This code has been declared by its author to be Public Domain code.

Download source code

File attributes by JoshK2011
Note that you must call ShowFile() before a hidden file can be read with ReadFile().
SuperStrict

Import pub.win32

Private

Const FILE_ATTRIBUTE_HIDDEN:Int=$2

Extern "win32"
	Function SetFileAttributesA(lpFileName$z,dwFileAttributes:Int)
	Function GetFileAttributesA:Int(lpFileName$z)
EndExtern

Public

Function HideFile(path:String)
	Local attrib:Int
	attrib=GetFileAttributesA(path)
	If Not (FILE_ATTRIBUTE_HIDDEN & attrib)
		SetFileAttributesA(path,attrib|FILE_ATTRIBUTE_HIDDEN)
	EndIf
EndFunction

Function ShowFile(path:String)
	Local attrib:Int
	attrib=GetFileAttributesA(path)
	If (FILE_ATTRIBUTE_HIDDEN & attrib)
		SetFileAttributesA(path,attrib~FILE_ATTRIBUTE_HIDDEN)	
	EndIf
EndFunction

Function FileHidden:Int(path:String)
	Local attrib:Int
	attrib=GetFileAttributesA(path)
	If (FILE_ATTRIBUTE_HIDDEN & attrib)
		Return True
	EndIf
EndFunction

Comments

None.

Code Archives Forum