Check if drive is HDD possible?

BlitzMax Forums/BlitzMax Beginners Area/Check if drive is HDD possible?

Grisu(Posted 2005) [#1]
Hello!

Is there a way to check if the drive a program is started from is a HDD/USB-STICK or non re-writeable CD/DVD-ROM?

Thanks.


Stoop Solo(Posted 2005) [#2]
A pretty crude sort of half-effective method might be to read the file attributes of either the executable or one of its resource files and see if the read-only attribute is set. Unless it has been set that way on the medium by the user or the installer, you could assume that a read-only flag would indicate a CD or non-writable media.


JazzieB(Posted 2005) [#3]
Or, you could try and open a file for writing only, and see if a file handle is returned. If yes, it's writeable (so HDD or other), if not it's a CD drive. If it turns out to be a HDD, close the file and then delete it again.


Grisu(Posted 2005) [#4]
Jazz, you mean this way:

out=WriteStream("write.tmp")
if not out then
hdd_found=false
closefile(out)
else
hdd_found=True
closefile(out)
deletefile(out)
endif

That's nice and simple! :)


JazzieB(Posted 2005) [#5]
Yeah, just like that. I'd try it on a CD ROM or a write-protected floppy to make sure it actually works. You probably won't need the CloseFile() if the stream wasn't opened though.


deps(Posted 2005) [#6]
If on a non-readonly media, how can you be sure the file isn't replaced with a new and empty one ready for writing? (until it's too late, that is)


JazzieB(Posted 2005) [#7]
Because usually you'd try and open a file for writing in your program's directory, so you'd know that whatever filename you are using for this purpose wouldn't be a file that is actually used by the game.

Or, you could check to see if a file already exists with that name and if it does, use another one. It would be a simple matter of going through 'test1.dat', 'test2.dat', etc.