Getcurrentdrive()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Getcurrentdrive()

Post by Simo_na »

Please, add similar to GetCurrentDirectory() like

Getcurrentdrive()

it is true that you can go to it with coding but in this way it is much faster
Thank you

I apologize for posting this in the wrong section :(
BarryG
Addict
Addict
Posts: 3325
Joined: Thu Apr 18, 2019 8:17 am

Re: Getcurrentdrive()

Post by BarryG »

For Windows, it's as simple as this:

Code: Select all

Debug Left(GetCurrentDirectory(),2) ; Returns "C:"
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Getcurrentdrive()

Post by Simo_na »

Getcurrentdrive() = Left(GetCurrentDirectory(),2) ; Returns "C:"
for a single drive...and that's fine but ...
Getcurrentdrives() ?
i would like to detect all drivers are present, like
Getcurrentdrives() = Returns "C:" - Returns "D:" - Returns "F:"

:)
User avatar
Lord
Addict
Addict
Posts: 849
Joined: Tue May 26, 2009 2:11 pm

Re: Getcurrentdrive()

Post by Lord »

Maybe something like this (Windows only):

Code: Select all

Enumeration
  #DriveWindow
EndEnumeration
Enumeration
  #DrivesList
EndEnumeration

Procedure.s GetDrives()
  DriveName$=Space(#MAX_PATH)
  OpenWindow(#DriveWindow, 10, 10, 232, 120, "Get Drives", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ListIconGadget(#DrivesList, 0, 0, WindowWidth(#DriveWindow), WindowHeight(#DriveWindow), "Drive", 64)
  AddGadgetColumn(#DrivesList, 1, "Name", 128)
  j=0
  For i=65 To 90
    Dir.s=Chr(i)+":\"
    If FileSize(dir)=-2
      GetVolumeInformation_(Dir,@DriveName$,255,0,0,0,0,255)
      AddGadgetItem(#DrivesList, -1, Dir+Chr(10)+DriveName$)
      AddKeyboardShortcut(#DriveWindow, i, i)
      L=Len(DriveName$)
      If L>LL
        LL=L
      EndIf
    EndIf
  Next
  Repeat
    Event=WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndProcedure

GetDrives()
Image
AZJIO
Addict
Addict
Posts: 1364
Joined: Sun May 14, 2017 1:48 am

Re: Getcurrentdrive()

Post by AZJIO »

Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Getcurrentdrive()

Post by Marc56us »

The current drive can also be:
- UNC ( \\server\share)
- MTP (i.e smartphone connected by USB)

PS. To avoid confusion between GetCurrentDrive and GetCurrentDrives, ask (or code?) a function name like GetAvailableDrives()
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Getcurrentdrive()

Post by Simo_na »

Marc56us wrote: Sat Apr 23, 2022 2:34 pm a function name like GetAvailableDrives()
Yes some sort of code like the ones do ye have posted
enclosed in a simpler command.

Thank you
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Getcurrentdrive()

Post by blueb »

I have this in my Templates folder:

Code: Select all

For Drive = 'A' To 'Z' ; infratec Oct 2019
  Dir = ExamineDirectory(#PB_Any, Chr(Drive) + ":/", "*")
  If Dir
    Debug Chr(Drive)
    FinishDirectory(Dir)
  EndIf
Next Drive
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply