How can a HDD serial# locate a Drive?

MPW

Well-known Member
Joined
Oct 7, 2009
Messages
551
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am using Excel 2003 to backup files automatically to 2 external drives.
The user initially selects the drives for the project to reside on. Since these removable drives could be unplugged and reattached, there is a strong chance that they will have different drive letters assigned.

Instead of requiring the user to continually browse for the drive I would like to use the HDD serial number (since it will never change) to locate the target and copy the files. I know that I could loop through the drives but I would rather just use the copy command.
Example: FileCopy "C:\Original_File", "E:\Copied_File"

My question is how do I write the command using the serial number instead of the drive letter.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Can get path and serial number like this :
Code:
'========================================================================================
'- GET EXTERNAL HARD DRIVES (includes flash drives)
'========================================================================================
Sub GET_EXTERNAL_DRIVES()
    Dim FSO, Drive, Counter
    '------------------------------------------------------------------------------------
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Counter = 0
    '------------------------------------------------------------------------------------
    '- LOOP ALL DRIVES
    For Each Drive In FSO.drives
        If Drive.isready And Drive.drivetype = 1 Then
            Counter = Counter + 1
            MsgBox ("Path   :  " & Drive.Path & "\" & vbCr _
                  & "Serial : " & Drive.serialnumber)
        End If
    Next
    '------------------------------------------------------------------------------------
    MsgBox ("Found " & Counter & " external drive(s).")
End Sub
'========================================================================================
 

MPW

Well-known Member
Joined
Oct 7, 2009
Messages
551
Office Version
  1. 365
Platform
  1. Windows
Thanks Brian,

I had decided to go with a For Loop to match up the pre-selected Serial number. Once it finds the number I just wrote the FileCopy command as usual. I did like the way you wrote the For Loop, it was a little more straight forward then what I have been using.

Mark
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,493
Messages
5,832,015
Members
430,104
Latest member
briannnnleong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top