Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to find out the drive letter. 1

Status
Not open for further replies.

ID10T16

Technical User
Sep 22, 2000
160
US
Ok, I'm trying to find some way to test if a certain CD is in a drive (probably by looking for a special file) and then taking that drive letter and making it a variable. Then I want to take that variable and use it to create a command that calls a program from the CD.

From some poking around online, It would seem that something like this would work:

Dim drive
if filesys.FileExists("d:\test.txt") then
drive= "D"
else
drive= "E"
end if

It has been a LONG time since I have done ANY programming or scripting, so it's like I'm learning all over again.

I'm sure I'm either almost there or so far away that it's comical.

Regardless, I will be incredibly grateful to any help anyone can offer.

Thanx all
 
To prepare for the search, you have to establish your targets. This is how you enum drivers and identify cd-rom.
[tt]
set fso=createobject("scripting.filesystemobject")
for each d in fso.drives
info=d.driveletter & vbcrlf & d.drivetype & vbcrlf & d.isready
if d.drivetype=4 then
info=info & vbcrlf & "This is a cd-rom."
if d.isready then
info=info & vbcrlf & "It is ready (with disk inserted inside it)."
else
info=info & vbcrlf & "It is not ready (no disk is inserted inside it)."
end if
end if
wscript.echo info
next
set fso=nothing
[/tt]
 
Thank you for your help, however I somehow got it to work like I wanted.

Here's what I used.

DIM fso, NewPC, drive


Set fso = CreateObject("Scripting.FileSystemObject")
Set NewPC = fso.CreateTextFile("c:\OldPC.bat", True)
if fso.FileExists("D:\test.txt") Then
drive = "D:\"
end if
if fso.FileExists("E:\test.txt") Then
drive = "E:\"
end if
if fso.FileExists("C:\test.txt") Then
drive = "X:\"
end if
NewPC.WriteLine (drive & "file.reg")
NewPC.Close

It get's the info that I need and is fairly simple.

Thank you again for your help
 
Maybe I was not answering your question. I just wanted to show you how to script well.

ps:As a side note, what if they all exist and drive return "x:\" and that's what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top