Find the letter of drive by his name [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Find the letter of drive by his name [Resolved]

Post 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
Last edited by Kwai chang caine on Sun Apr 21, 2024 11:40 am, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Find the letter of drive by his name

Post by Piero »

Buy a Mac? :mrgreen:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Find the letter of drive by his name

Post 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:
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Find the letter of drive by his name

Post 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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Find the letter of drive by his name

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Find the letter of drive by his name

Post 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
ImageThe happiness is a road...
Not a destination
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Find the letter of drive by his name

Post 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
Last edited by Piero on Mon Apr 22, 2024 2:02 pm, edited 2 times in total.
User avatar
Piero
Addict
Addict
Posts: 1040
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Find the letter of drive by his name

Post 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:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post by Kwai chang caine »

Yes...i know :oops:
And don't forget the "brand new in its box" :mrgreen: Image
:lol:
ImageThe happiness is a road...
Not a destination
Post Reply