Page 1 of 1

Getcurrentdrive()

Posted: Sat Apr 23, 2022 9:53 am
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 :(

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 11:11 am
by BarryG
For Windows, it's as simple as this:

Code: Select all

Debug Left(GetCurrentDirectory(),2) ; Returns "C:"

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 1:36 pm
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:"

:)

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 1:59 pm
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()

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 2:20 pm
by AZJIO

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 2:34 pm
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()

Re: Getcurrentdrive()

Posted: Sat Apr 23, 2022 4:09 pm
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

Re: Getcurrentdrive()

Posted: Sun Apr 24, 2022 12:44 pm
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