Skip to content

Instantly share code, notes, and snippets.

@peterblazejewicz
Created May 11, 2011 11:08
Show Gist options
  • Save peterblazejewicz/966291 to your computer and use it in GitHub Desktop.
Save peterblazejewicz/966291 to your computer and use it in GitHub Desktop.
simple wrapper around Kernel32.dll GetDriveType function
package
{
import mdm.DLL;
import mdm.System;
public class Kernel32
{
/* The drive type cannot be determined. */
public static const DRIVE_UNKNOWN:int = 0;
/* The root path is invalid; for example, there is no volume mounted at the specified path. */
public static const DRIVE_NO_ROOT_DIR:int = 1;
/* The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader. */
public static const DRIVE_REMOVABLE:int = 2;
/* The drive has fixed media; for example, a hard drive or flash drive. */
public static const DRIVE_FIXED:int = 3;
/* The drive is a remote (network) drive. */
public static const DRIVE_REMOTE:int = 4;
/* The drive is a CD-ROM drive. */
public static const DRIVE_CDROM:int = 5;
public static const DRIVE_RAMDISK:int = 6;
/**
* Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.
* see: http://msdn.microsoft.com/en-us/library/aa364939(v=vs.85).aspx
* @parameter driveRootPath The root directory for the drive.
* A trailing backslash is required.
* If this parameter is NULL, the function uses the root of the current directory.
* @return The return value specifies the type of drive, which can be one of the following values.
*/
public static function GetDriveType(driveRootPath:String):int
{
// reuse instance to preserve memory if not yet cleared
if(Kernel32.dll != null)
{
Kernel32.dll.clear();
} else
{
// path in system
var path:String = mdm.System.Paths.system+"Kernel32.dll";
Kernel32.dll = new mdm.DLL(path);
// very simple error handling
if(Kernel32.dll == null)
{
return Kernel32.DRIVE_UNKNOWN;
};
};
Kernel32.dll.addParameter("string", driveRootPath);
var results:int = Kernel32.dll.call("integer", "GetDriveTypeA") as int;
Kernel32.dll.clear();
Kernel32.dll.close();
Kernel32.dll = null;
return results;
};
//
private static var dll:mdm.DLL = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment