Lister les lecteurs
Voici un code qui vous permettra de lister les différents lecteurs possibles de votre disque.
- Systèmes :
- Windows
- Linux
MacOs
- PureBasic 4.30
CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux ;{ Structure mntent mnt_fsname.s mnt_dir.s mnt_type.s mnt_opts.s mnt_freq.l mnt_passno.l EndStructure ;} CompilerEndSelect Structure S_Drives drive.s{255} options.s{255} unix_fsname.s{255} unix_type.s{255} unix_freq.l unix_passno.l windows_type.l EndStructure Structure S_ListDrives nb.l ptrMem.l EndStructure ProcedureDLL System_GetDrives() Protected Dim MyDrives.S_Drives(0) Protected *ListDrives.S_ListDrives = AllocateMemory(SizeOf(S_ListDrives)) Protected lSize.l CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Windows ;{ Protected sDrives.s = Space(255) Protected lRes.l = GetLogicalDriveStrings_(255, sDrives) Protected lOffset.l Repeat MyDrives(lSize)\drive = PeekS(@sDrives+lOffset,4) MyDrives(lSize)\windows_type = GetDriveType_(@MyDrives(lSize)\drive) lOffset + 4 lSize +1 ReDim MyDrives.S_Drives(lSize) Until PeekS(@sDrives+lOffset,4)="" ;} CompilerCase #PB_OS_Linux ;{ ; http://man.developpez.com/man3/getmntent.3.php Protected hMtab.l, hPointer.l Protected *info.mntent hMtab = setmntent_("/etc/mtab", "r") If hMtab hPointer = getmntent_(hMtab) While hPointer *info = hPointer MyDrives(lSize)\drive = *info\mnt_dir MyDrives(lSize)\options = *info\mnt_opts MyDrives(lSize)\unix_fsname = *info\mnt_fsname MyDrives(lSize)\unix_type = *info\mnt_type MyDrives(lSize)\unix_freq = *info\mnt_freq MyDrives(lSize)\unix_passno = *info\mnt_passno lSize +1 ReDim MyDrives.S_Drives(lSize) hPointer = getmntent_(hMtab) Wend endmntent_(hMtab) Else ProcedureReturn #False EndIf ;} CompilerEndSelect *ListDrives\nb = lSize *ListDrives\ptrMem = AllocateMemory(lSize * SizeOf(S_Drives)) MoveMemory(@MyDrives(), *ListDrives\ptrMem, lSize * SizeOf(S_Drives)) ProcedureReturn *ListDrives EndProcedure lMem = System_GetDrives() Define.S_ListDrives DrivesListing MoveMemory(lMem, @DrivesListing, SizeOf(S_ListDrives)) Dim Drives.S_Drives(DrivesListing\nb) MoveMemory(DrivesListing\ptrMem, @Drives(), DrivesListing\nb * SizeOf(S_Drives)) For Inc = 0 To DrivesListing\nb -1 Debug "Drive <" + Drives(Inc)\drive Debug "Options < " + Drives(Inc)\options CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux ;{ Debug Drives(Inc)\unix_fsname ;} CompilerCase #PB_OS_Windows ;{ Debug "Type < "+Str(Drives(Inc)\windows_type) ;} CompilerEndSelect Next
Ajouter un commentaire