Hidden Files

BlitzMax Forums/BlitzMax Beginners Area/Hidden Files

ima747(Posted 2009) [#1]
Doesn't seem like this is in the blitzmax core and I couldn't find any examples or mods that will do this, maybe I just missed something.

I need to be able to determine if a file/folder is hidden cross platform. Seems like there would be a FileFlags() or FileVisible() function like there's FileSize() and FileType() etc...

On mac/linux one can hack it by checking if the name starts with a "." but on a windows I think you need to call a system function and I'm lost.


grable(Posted 2009) [#2]
I was going to say FileMode.. but quicly realized it wont do anything other than read,write,execute...

What you want is GetFileAttributes, check this page for more info: http://msdn.microsoft.com/en-us/library/ee332330(VS.85,lightweight).aspx


Dabhand(Posted 2009) [#3]
EDIT: Nothing, I'm going mad I think! ;)

Dabz


ima747(Posted 2009) [#4]
Thanks grable, I don't recall how to call system things like that, any chance you could hit me with an example?


grable(Posted 2009) [#5]
Sure, since its so small you get the whole thing too ;)
SuperStrict

Const FILE_ATTRIBUTE_ARCHIVE:Int = $0020
Const FILE_ATTRIBUTE_COMPRESSED:Int = $0800
Const FILE_ATTRIBUTE_DEVICE:Int = $0040
Const FILE_ATTRIBUTE_DIRECTORY:Int = $0010
Const FILE_ATTRIBUTE_ENCRYPTED:Int = $4000
Const FILE_ATTRIBUTE_HIDDEN:Int = $0002
Const FILE_ATTRIBUTE_NORMAL:Int = $0080
Const FILE_ATTRIBUTE_READONLY:Int = $0001
Const FILE_ATTRIBUTE_SYSTEM:Int = $0004
Const FILE_ATTRIBUTE_TEMPORARY:Int = $0100

Extern "Win32"
	Function GetFileAttributesW:Int( fn$w)
EndExtern

Function IsFileHidden:Int( fn:String)
	Return (GetFileAttributesW(fn) & FILE_ATTRIBUTE_HIDDEN) <> 0
EndFunction



ima747(Posted 2009) [#6]
Thanks grable. Here's what I've got.

FileHidden.bmx
SuperStrict

?Win32
Const FILE_ATTRIBUTE_ARCHIVE:Int = $0020
Const FILE_ATTRIBUTE_COMPRESSED:Int = $0800
Const FILE_ATTRIBUTE_DEVICE:Int = $0040
Const FILE_ATTRIBUTE_DIRECTORY:Int = $0010
Const FILE_ATTRIBUTE_ENCRYPTED:Int = $4000
Const FILE_ATTRIBUTE_HIDDEN:Int = $0002
Const FILE_ATTRIBUTE_NORMAL:Int = $0080
Const FILE_ATTRIBUTE_READONLY:Int = $0001
Const FILE_ATTRIBUTE_SYSTEM:Int = $0004
Const FILE_ATTRIBUTE_TEMPORARY:Int = $0100

Extern "Win32"
	Function GetFileAttributesW:Int( fn$w)
EndExtern
?

Function FileHidden:Int(path:String)
	?MacOS
	return Left(StripDir(path), 1) = "."
	?Linux
	return Left(StripDir(path), 1) = "."
	?Win32
	Return (GetFileAttributesW(path) & FILE_ATTRIBUTE_HIDDEN) <> 0
	?
End Function


Not well tested but it works nicely where I'm using it. IsFileHidden is a better name for the function but I wanted to keep it consistent with the built in functions for my own limited sanity.


Czar Flavius(Posted 2009) [#7]
Shorthand - you can just say Return Left(StripDir(path), 1) = "." on one line :)


ima747(Posted 2009) [#8]
ah good call czar, code updated