Hi, can someone tell me how call drive letters, for example if i want to refer to files on a removable disk i would need something like %drive% as the disk might have a different letter on different PC's.
Many thanks
Drive Letters
Moderators: Dorian (MJT support), JRL
I am not clear how exactly I would do this from MS, but you could integrate with a VBScript and call the results into your MS script.
Open Notepad and paste the code below into it.
Save the document as drives.vbs (be sure to change text file to all files in the save box drop-down)
Run the drives.vbs file by clicking on it.
The Code: (Many Thanks G. Born)
Option Explicit
' Drive type constants
Const Unknown = 0
Const Removable = 1 ' Removable medium
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Title
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = " Unknown "
drtype(1) = " Removable "
drtype(2) = " Fixed "
drtype(3) = " Remote "
drtype(4) = " CDROM "
drtype(5) = " RAMDisk "
Text = "Drives" & vbCrLf & vbCrLf
Title = "From Macro Scheduler Post"
' Create FileSystemObject object to access the file system.
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter & vbTab ' Drive letter
Text = Text & drtype(curDrive.DriveType)
Select Case curDrive.DriveType ' Identify drive type.
Case Removable ' Removable medium
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case CDROM ' CD-ROM
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case Remote
Text = Text & curDrive.ShareName ' Network drive
Case Else ' Other medium
Text = Text & curDrive.VolumeName ' Local drive
End Select
Text = Text & vbCrLf
Next
MsgBox Text, vbOKOnly + vbInformation, Title
'*** End
______
Good Luck, Ed
Open Notepad and paste the code below into it.
Save the document as drives.vbs (be sure to change text file to all files in the save box drop-down)
Run the drives.vbs file by clicking on it.
The Code: (Many Thanks G. Born)
Option Explicit
' Drive type constants
Const Unknown = 0
Const Removable = 1 ' Removable medium
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Title
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = " Unknown "
drtype(1) = " Removable "
drtype(2) = " Fixed "
drtype(3) = " Remote "
drtype(4) = " CDROM "
drtype(5) = " RAMDisk "
Text = "Drives" & vbCrLf & vbCrLf
Title = "From Macro Scheduler Post"
' Create FileSystemObject object to access the file system.
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter & vbTab ' Drive letter
Text = Text & drtype(curDrive.DriveType)
Select Case curDrive.DriveType ' Identify drive type.
Case Removable ' Removable medium
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case CDROM ' CD-ROM
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case Remote
Text = Text & curDrive.ShareName ' Network drive
Case Else ' Other medium
Text = Text & curDrive.VolumeName ' Local drive
End Select
Text = Text & vbCrLf
Next
MsgBox Text, vbOKOnly + vbInformation, Title
'*** End
______
Good Luck, Ed
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Macro Scheduler version:
Ed, if you're going to post code here could you please try to make it work in Macro Scheduler, so that I don't have to keep rewriting your code ;-)
And also, can you use the Code button when pasting code, to preserve formatting.
Code: Select all
VBSTART
Option Explicit
Function GetDrives
' Drive type constants
Const Unknown = 0
Const Removable = 1 ' Removable medium
Const Fixed = 2 ' Fixed medium (hard disk)
Const Remote = 3 ' Network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Title
Dim fso, oDrive, curDrive ' Object variables
Dim drtype(6)
drtype(0) = " Unknown "
drtype(1) = " Removable "
drtype(2) = " Fixed "
drtype(3) = " Remote "
drtype(4) = " CDROM "
drtype(5) = " RAMDisk "
Text = "Drives" & vbCrLf & vbCrLf
Title = "From Macro Scheduler Post"
' Create FileSystemObject object to access the file system.
Set fso = CreateObject("Scripting.FileSystemObject")
Set oDrive = fso.Drives ' Get Drives collection.
For Each curDrive In oDrive ' All drive objects
Text = Text & curDrive.DriveLetter & vbTab ' Drive letter
Text = Text & drtype(curDrive.DriveType)
Select Case curDrive.DriveType ' Identify drive type.
Case Removable ' Removable medium
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case CDROM ' CD-ROM
If curDrive.IsReady Then
Text = Text & curDrive.VolumeName ' Local drive
End If
Case Remote
Text = Text & curDrive.ShareName ' Network drive
Case Else ' Other medium
Text = Text & curDrive.VolumeName ' Local drive
End Select
Text = Text & vbCrLf
Next
GetDrives = Text
End Function
VBEND
VBEval>GetDrives,drive_info
MessageModal>drive_info
Ed, if you're going to post code here could you please try to make it work in Macro Scheduler, so that I don't have to keep rewriting your code ;-)
And also, can you use the Code button when pasting code, to preserve formatting.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
You could put a unique file on the root of the drive.
Then loop throught the drive letters as variables, seeing IfFileExist>%drive%:\filename.ext
When it exists, then you know the Drive letter that you need...%drive%
Then loop throught the drive letters as variables, seeing IfFileExist>%drive%:\filename.ext
When it exists, then you know the Drive letter that you need...%drive%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Not a troll. Your contributions are welcome! Keep contributing!
I just posted a link to the Merlin script on my blog:
http://www.mjtnet.com/blog/
I just posted a link to the Merlin script on my blog:
http://www.mjtnet.com/blog/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?