Page 1 of 1

Find the letter of drive by his name [Resolved]

Posted: Sat Apr 20, 2024 8:49 pm
by Kwai chang caine
Hello at all

I know how find the name of a drive when i have his letter

Code: Select all

 Procedure.s Lecteur_LettreEnNom(LettreLecteur.s) 
  sVolumeNameBuffer.s = Space(#MAX_PATH) 
  lpVolumeNameBuffer.l = @sVolumeNameBuffer 
  nVolumeNameSize.l = #MAX_PATH 
  GetVolumeInformation_(@LettreLecteur, lpVolumeNameBuffer, nVolumeNameSize, 0, 0, 0, 0, 0) 
  ProcedureReturn sVolumeNameBuffer  
 EndProcedure 
 
 Debug Lecteur_LettreEnNom("C:\")
But i don't know the oposite :|
Then, with the first code, i have create a function who works fine, but have you the direct API for replace my dirty code with enumeration of all drives :oops:

Code: Select all

Procedure.s Lecteur_NomEnLettre(NomLecteur.s)
 
 drives_avail = GetLogicalDrives_()
 sVolumeNameBuffer.s = Space(#MAX_PATH) 
 nVolumeNameSize.l = #MAX_PATH 
 
 For i = 0 To 25
  
  If drives_avail >> i & 1
   
   LettreLecteur$ = Chr(i + 65) + ":\"
   lpVolumeNameBuffer.l = @sVolumeNameBuffer 
   GetVolumeInformation_(@LettreLecteur$, lpVolumeNameBuffer, nVolumeNameSize, 0, 0, 0, 0, 0) 
   
   If NomLecteur = sVolumeNameBuffer
    ProcedureReturn LettreLecteur$
   EndIf
   
  EndIf	
  
 Next
 
EndProcedure

Debug Lecteur_NomEnLettre("Windows")
Have a good day

Re: Find the letter of drive by his name

Posted: Sat Apr 20, 2024 9:33 pm
by Piero
Buy a Mac? :mrgreen:

Re: Find the letter of drive by his name

Posted: Sun Apr 21, 2024 10:41 am
by Kwai chang caine
I have several MAC...carefully packaged in their original carton :mrgreen:

=================================================================================================================
ATTENTION !!! ATTENTION !!! ATTENTION !!! ATTENTION !!!
............................. This panel is for MAC lovers ...................................
Don't read on...
KCC corporation disclaims all liability regarding an attempt to read the following text,
which could result in a heart attack
:?
===================================================================================================

But before, for to be right in my boots, the first thing i have do ?
A dual boot.....with WINDOWS in the default boot when it was possible 8)

Yes ...i know ..i'm surely the LUCIFER brother :lol:

Image

What do you want ???
We don't change a losing team
:mrgreen:

Re: Find the letter of drive by his name

Posted: Sun Apr 21, 2024 11:28 am
by infratec
To reduce your enumeration:

Code: Select all

EnableExplicit

Structure Char_Structure
  Char.s{1}
EndStructure


Define Chars.i
Define Drive$
Define *Drives
Define *Ptr.Char_Structure

*Drives = AllocateMemory(1024)
If *Drives
  *Ptr = *Drives
  
  Chars = GetLogicalDriveStrings_(MemorySize(*Drives), *Drives)
  
  While Chars
    If *Ptr\Char = #Null$
      Debug Drive$
      Drive$ = ""
    Else
      Drive$ + *Ptr\Char
    EndIf
    *Ptr + SizeOf(Character)
    Chars - 1
  Wend
  
  FreeMemory(*Drives)
EndIf

Re: Find the letter of drive by his name

Posted: Sun Apr 21, 2024 11:35 am
by infratec
Piero wrote: Sat Apr 20, 2024 9:33 pm Buy a Mac? :mrgreen:
This does not solve the problem:
Plugin several USB disks an find the mountpoint by the name of the disk.

Re: Find the letter of drive by his name

Posted: Sun Apr 21, 2024 11:40 am
by Kwai chang caine
Hello Master INFRATEC,

Thanks a lot for your help 8)
I replace mine immediately by your nice code :wink:

So if you don't give me the API, i suppose she not exist the opposite of GetVolumeInformation_() :|
Never mind, that works like that, and in KCC world it's already a miracle :lol:
Like we say in FRANCE "We are still not going to be more royalist than the king" :mrgreen:

Have a very good day

Re: Find the letter of drive by his name

Posted: Mon Apr 22, 2024 8:00 am
by Piero
infratec wrote: Sun Apr 21, 2024 11:35 am
Piero wrote: Sat Apr 20, 2024 9:33 pm Buy a Mac? :mrgreen:
This does not solve the problem:
Plugin several USB disks an find the mountpoint by the name of the disk.
this can be a solution (via shell or Terminal on Mac):

Code: Select all

diskutil info 'USB-NAME' | grep 'Mount Point' | grep -Eo '/.*'
Edit: Put a better example

Re: Find the letter of drive by his name

Posted: Mon Apr 22, 2024 8:11 am
by Piero
Kwai chang caine wrote: Sun Apr 21, 2024 10:41 amA dual boot.....with WINDOWS in the default boot
This is beyond abomination! :shock: :x :lol:

Re: Find the letter of drive by his name [Resolved]

Posted: Mon Apr 22, 2024 10:05 am
by Kwai chang caine
Yes...i know :oops:
And don't forget the "brand new in its box" :mrgreen: Image
:lol: