www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - listRoots?

reply "Jan Hanselaer" <jan.hanselaer gmail.com> writes:
Hi

At first sight I can't find a way to get all the partitions on the user his 
system.
I'm looking for something like File.listRoots() in Java.
Anyone knows a way to do this?

Thanks
Jan 
May 12 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Content-Type: text/plain

Jan Hanselaer Wrote:
 Hi
 
 At first sight I can't find a way to get all the partitions on the user his 
 system.
 I'm looking for something like File.listRoots() in Java.
 Anyone knows a way to do this?

Does this do what you want (see attached). Output on my system is: HDD: [C:\,D:\,G:\] FDD: [A:\] CDD: [E:\] Regan Heath
May 13 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
Content-Type: text/plain

Just realised I could template it and easily support all types.  Attached is a
new one.
May 13 2007
next sibling parent "Jan Hanselaer" <jan.hanselaer gmail.com> writes:
"Regan Heath" <regan netmail.co.nz> schreef in bericht 
news:f27n2v$2oju$1 digitalmars.com...
 Just realised I could template it and easily support all types.  Attached 
 is a new one.

--------------------------------------------------------------------------------
 import std.stdio, std.string;

 alias std.string.toStringz CSTR;

 import std.c.windows.windows;

 extern(Windows)
 {
 DWORD GetLogicalDrives();
 UINT GetDriveTypeA(LPCSTR lpRootPathName);
 UINT GetDriveTypeW(LPCWSTR lpRootPathName);
 const UINT DRIVE_UNKNOWN     = 0; //The drive type cannot be determined.
 const UINT DRIVE_NO_ROOT_DIR = 1; //The root path is invalid; for example, 
 there is no volume is mounted at the path.
 const UINT DRIVE_REMOVABLE   = 2; //The drive has removable media; for 
 example, a floppy drive, thumb drive, or flash card reader.
 const UINT DRIVE_FIXED       = 3; //The drive has fixed media; for 
 example, a hard drive or flash drive.
 const UINT DRIVE_REMOTE      = 4; //The drive is a remote (network) drive.
 const UINT DRIVE_CDROM       = 5; //The drive is a CD-ROM drive.
 const UINT DRIVE_RAMDISK     = 6; //The drive is a RAM disk.
 }

 char[][] LocalDrives()
 {
 DWORD mask = GetLogicalDrives();
 char[] drive = new char[3];
 char[][] list;

 drive[1..3] = ":\\";
 for(int i = 0; i < 26; i++)
 {
 if (mask & 0x1<<i)
 {
 drive[0] = 'A'+i;
 list ~= drive.dup;
 }
 }

 return list;
 }

 template SortDrive(UINT TYPE) { char[][] SortDrive() {
 char[][] list;

 foreach(drive; LocalDrives())
 {
 switch(GetDriveTypeA(CSTR(drive)))
 {
 case TYPE:
 list ~= drive;
 break;
 default:
 break;
 }
 }

 return list;
 }}

 alias SortDrive!(DRIVE_FIXED) FixedDrives;
 alias SortDrive!(DRIVE_REMOVABLE) RemovableDrives;
 alias SortDrive!(DRIVE_REMOTE) RemoteDrives;
 alias SortDrive!(DRIVE_CDROM) CdDrives;
 alias SortDrive!(DRIVE_RAMDISK) RamDisks;

 void main()
 {
 writef("Fixed    : ",FixedDrives(),"\n");
 writef("Removable: ",RemovableDrives(),"\n");
 writef("Remote   : ",RemoteDrives(),"\n");
 writef("Cd       : ",CdDrives(),"\n");
 writef("Ramdisk  : ",RamDisks(),"\n");
 }

That does the trick. Thanks a lot!
May 13 2007
prev sibling next sibling parent Derek Parnell <derek nomail.afraid.org> writes:
On Sun, 13 May 2007 14:57:35 -0400, Regan Heath wrote:

 Just realised I could template it and easily support all types.  Attached is a
new one.

This works without fault on my XP SP2 system. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 14/05/2007 4:11:29 PM
May 13 2007
prev sibling next sibling parent Regan Heath <regan netmail.co.nz> writes:
I should also state "This code is public domain".  That is, all code I posted
in this the "listRoots?" thread is public domain.

Regan Heath

p.s. Of course mentioning my name in your code comments or wherever would make
me happy ;)
May 14 2007
prev sibling parent reply BCS <ao pathlink.com> writes:
Reply to Regan,

 Just realised I could template it and easily support all types.
 Attached is a new one.
 

Would you loke to add this to scrapple? http://www.dsource.org/projects/scrapple
May 14 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
BCS Wrote:
 Reply to Regan,
 
 Just realised I could template it and easily support all types.
 Attached is a new one.
 

Would you loke to add this to scrapple? http://www.dsource.org/projects/scrapple

For some reason that link isn't working for me. I assume it's a library of sorts? Assuming there is no problem with the fact that I made my code public domain feel free to add the code I posted to scrapple. I'd appreciate a mention somewhere even if it's just in a comment by the code itself. Regan Heath
May 15 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Regan Heath wrote:
 BCS Wrote:
 Reply to Regan,

 Just realised I could template it and easily support all types.
 Attached is a new one.

http://www.dsource.org/projects/scrapple

For some reason that link isn't working for me.

It looks like dsource is down (though I can still ping it).
 I assume it's a library of sorts?

Of sorts. It's basically an "miscellaneous" project, containing useful stuff that for one reason or another isn't hosted elsewhere.
May 15 2007
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Frits van Bommel wrote:
 Regan Heath wrote:
 BCS Wrote:
 Reply to Regan,

 Would you loke to add this to scrapple?



 I assume it's a library of sorts?


 Of sorts. It's basically an "miscellaneous" project, containing useful 
 stuff that for one reason or another isn't hosted elsewhere.

Speaking of which, I would love it if there were some place where one could browse for all known D projects, with a keyword index. Probably Dsource is the closest thing to a clearing house for D code, but some people just want to host their own stuff. Anyway, I'm thinking of a PyPI (Python Package Index) type thing. You don't have to host your project on PyPI, though you can, but whether you do or not, you can register your project, supply keywords, and a brief description and a pointer to where the code can be found. I was thinking DSSS was going to sprout something like that, but as far as I know, DSSS finds -net packages via some less public route. --bb
May 15 2007