hidden & system files.

BlitzMax Forums/BlitzMax Programming/hidden & system files.

Jesse(Posted 2008) [#1]
Is there any way to tell if a file is hidden and/or system file?
file mode does not show any reference to that.


Bremer(Posted 2008) [#2]
You should be able to use the GetAttr function from the windows system:

http://msdn.microsoft.com/en-us/library/aa364944.aspx

[edit] wrong link first time around.


Jesse(Posted 2008) [#3]
thanks,zawran

now how to wrap this in bmax? anybody?


SebHoll(Posted 2008) [#4]
This should work:

SuperStrict

?Win32
Import Pub.Win32	'Import WinAPI Libraries and Functions
?

Print IsFileHidden("C:\Temp\icon.ico")

Function IsFileHidden%( pFilepath$ )
	?Win32
	If (GetFileAttributesW( pFilePath) & FILE_ATTRIBUTE_HIDDEN) Then Return True
	?
EndFunction

Function IsSystemFile%( pFilepath$ )
	?Win32
	If (GetFileAttributesW( pFilePath) & FILE_ATTRIBUTE_SYSTEM) Then Return True
	?
EndFunction
I should perhaps point out that the function is only available on Windows 2000/XP/Vista PCs and so will not work on Windows 9X/NT.


Canardian(Posted 2008) [#5]
SuperStrict

Extern "WIN32"
	Function GetFileAttributes:Int(lpFileName:Byte Ptr)="GetFileAttributesA@4"
EndExtern

Function GetFileAttribs:String(FileName:String)
	Local s:String
	Local Mode:Int=GetFileAttributes(String.FromCString(FileName))
	If Mode &     1 =     1 s:+"R" ' Read only
	If Mode &     2 =     2 s:+"H" ' Hidden
	If Mode &     4 =     4 s:+"S" ' System
	If Mode &    16 =    16 s:+"D" ' Directory
	If Mode &    32 =    32 s:+"A" ' Archive
	If Mode &    64 =    64 s:+"$" ' device$
	If Mode &   256 =   256 s:+"T" ' Temporary
	If Mode &   512 =   512 s:+"P" ' Sparse
	If Mode &  1024 =  1024 s:+"L" ' Link
	If Mode &  2048 =  2048 s:+"C" ' Compressed
	If Mode &  4096 =  4096 s:+"O" ' Offline
	If Mode &  8192 =  8192 s:+"X" ' not indeXable
	If Mode & 16384 = 16384 s:+"E" ' Encrypted
	If Mode & 65536 = 65536 s:+"V" ' Virtual
	Return s
EndFunction

Print GetFileAttribs("testfile.txt")

Note that there are no \ chars in the external function definition, the code tag of this forum is just bugged and creates those.


Jesse(Posted 2008) [#6]
thanks a lot SebHoll and Lumooja. You guys have been a lot of help.