Re: check for drive letter before copying files.



On Apr 11, 10:23 pm, "shrpshtr" <shrps...@xxxxxxxxx> wrote:
hey all,

script newbie here and i am banging my head against my keyboard trying
to figure this one out. i am sure it is easy to all of the guru's
here. what i am trying to do is check to see if an assigned drive
letter (i: in this case) exists before i allow a script to copy data
to it. if it doesn't i want the script to continue as planned, if it
doesn't i want the script to prompt the end user to insert his/her usb
drive. i know there has to be a way to do it so any help would be
greatly appreciated. thanks in advance...

here is what i have so far.

Dim objfso, msg, i

drv = "i"
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(drv) Then
End If
Set i = objfso.GetDrive(drv)
If i.IsReady Then
Else
msg = "Please plug USB drive into laptop..."
End If
Else
msg = "Please plug USB drive into laptop..."
End If
Set objShell = CreateObject("Wscript.Shell")
objshell.Popup msg, AUTO_ANSWER, "Insert USB Drive", OK_Button

'first thing check the drive status, don't continue until it
'becomes available.

Do Until DriveStatus = True
DriveStatus = CheckDrive("i")
Loop

'some code down here to do some more stuff


'This function at the end of your code
Function CheckDrive(sDriveLetter)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.DriveExists(sDriveLetter) Then
Set i = objfso.GetDrive(sDriveLetter
If Not i.IsReady Then Wscript.Echo "Please plug USB drive into
laptop..."
CheckDrive = False
Else
Wscript.Echo "Please plug USB drive into laptop..."
CheckDrive = False
End If

CheckDrive = True
End Function


Hope this helps. As always watch for line wrapping.

-Nate
http://www.naterice.com

.


Loading