Login | |
|
 |
RE: I need help, please help, - 2/5/2008 5:50:40 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Okay, this is the prompt section Option Explicit 'Dim objWMIService, objItem, colItems Dim strComputer, strMbox 'On Error Resume Next strMbox = "." strMbox = msgBox("Please enter your usb key and press the enter key to continue") If strMbox = 1 Then strmbox ="." end if This is the usb section On Error Resume Next strComputer = "." arrDriveType = array("Unknown",_ "No Root Directory",_ "Removable Disk",_ "Local Disk",_ "Network Drive",_ "Compact Disk",_ "RAM Disk") set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk") For Each Disk in ColDisks strType = arrDriveType(Disk.DriveType) strID = Disk.DeviceID strSys = Disk.SystemName If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) end if If strMbox = 1 Then strMbox ="." End If Next they work fine apart, but when you add them together then do not work.
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 6:49:37 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
Believe it or not, all I had to do is define the variable. Code is posted below. Option Explicit 'Dim objWMIService, objItem, colItems Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys strMbox = "." strMbox = msgBox("Please enter your usb key and press the enter key to continue") If strMbox = 1 Then strmbox ="." end if strComputer = "." arrDriveType = array("Unknown",_ "No Root Directory",_ "Removable Disk",_ "Local Disk",_ "Network Drive",_ "Compact Disk",_ "RAM Disk") set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk") For Each Disk in ColDisks strType = arrDriveType(Disk.DriveType) strID = Disk.DeviceID strSys = Disk.SystemName If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) end if Next Time for the next section
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 6:52:42 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
I do believe it since you have Option Explicit which is good programming practice for VBS. So when you removed the global On Error Resume next which is bad programming practice, an error showed up that told you what was wrong.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 7:10:51 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
I have pieced all together and I receive some major issues. I do know that parts of the script are working correctly. I just get errors when I run it. Option Explicit Dim objWMIService, objItem, colItems Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys function getParent() fPath="\\bluewater\departments$\Information Technology\test\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(fPath) set oSubfolders = oFolder.Subfolders '***************************************************************************************************** strMbox = "." strMbox = msgBox("Please enter your usb key and press the enter key to continue") If strMbox = 1 Then strmbox ="." end if '***************************************************************************************************** strComputer = "." arrDriveType = array("Unknown",_ "No Root Directory",_ "Removable Disk",_ "Local Disk",_ "Network Drive",_ "Compact Disk",_ "RAM Disk") set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk") For Each Disk in ColDisks strType = arrDriveType(Disk.DriveType) strID = Disk.DeviceID strSys = Disk.SystemName If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) end if '****************************************************************************************************** for each oSubfolders in oSubfolders filePath=GetNewestFile(oSubfolders) if(instr(filePath, sToday)) then fileName = re.replace(GetFilenameFromPath(filePath),"") oFSO.CopyFile filePath , "\\bluewater\departments$\Information Technology\test\" & fileName , OverwriteExisting else Set objTextFile = oFSO.OpenTextFile _ (fPath & "exception" & date() & ".txt", ForAppending, True) objTextFile.WriteLine("output data") objTextFile.Close end if next 'end function
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 7:24:03 AM
|
|
 |
|
| |
dmp_92
Posts: 70
Score: 0
Joined: 2/1/2008
Status: offline
|
sorry about that, I have new code for the file transfer section. The last piece of this code. I do not receive any errors now, however I check to see if the file has been copied over to the usb key and it has not. Option Explicit 'Dim objWMIService, objItem, colItems Dim strComputer, strMbox, ArrDriveType, WMI, coldisks, disk, strtype, strID, strSys, UsbKey, file Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject") Dim objFolderA: Set objFolderA=objFSO.GetFolder("\\bluewater\departments$\Information Technology\test\") UsbKey=strID 'UsbKey="C:\FolderB\" strMbox = "." strMbox = msgBox("Please enter your usb key and press the enter key to continue") If strMbox = 1 Then strmbox ="." end if strComputer = "." arrDriveType = array("Unknown",_ "No Root Directory",_ "Removable Disk",_ "Local Disk",_ "Network Drive",_ "Compact Disk",_ "RAM Disk") set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDisks = WMI.ExecQuery("Select * from Win32_LogicalDisk") For Each Disk in ColDisks strType = arrDriveType(Disk.DriveType) strID = Disk.DeviceID strSys = Disk.SystemName If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) end if Next For Each file in objFolderA.Files If dateDiff("d", file.DateCreated, Date) < 2 Then 'copy file if it's "2 days old" objFSO.CopyFile file.Path, UsbKey End If Next Set objFSO=Nothing
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 7:31:37 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
Scripts run in a sequential fashion. They start at the first line, then the next, then the next, etc. The exception to this is flow control statements. Things like If - Then, For -Next, etc. So in your script, at the top before any thing has had a chance to really happen, you have: UsbKey=strID At this point strID contains nothing. So your statement says "Make UsbKey contain nothing". You never do anything else for the rest of the script to assign a value to UsbKey. So when the script gets to: objFSO.CopyFile file.Path, UsbKey You are telling it to "Copy the file to nothing" it just assumes that you are crazy and goes on about it's business since it doesn't know how to copy a file to nothing. You need to think about what your script is doing. At what point in the code do you know what the drive letter for the USB key is? At that point then you need to set UsbKey to contain the path where you want the file copied.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 7:52:23 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
You are close. The only time that you know which drive is the usb drive is when this: If strType = "Removable Disk" then Evaluates to true. So you need to do your assignment inside the If - Then block Like this: If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) UsbKey = strId end if However, if tou do that the copy still won't work. strID at that point would hold the drive letter of the usb key. So it hold's something like "V:". Obviously then when you get to this line: objFSO.CopyFile file.Path, UsbKey You would be telling it to copy the file to V:. But where on V:. The script does not know anything that you don't tell it or that it isn't told to find out on it's own. So to make the copy command correct, you would need to use this code for the assignment: If strType = "Removable Disk" then strMbox = MsgBox("USB drive letter is " & Disk.DeviceID) UsbKey = strId & "\FolderB\" end if Now you have told it exactly where to copy the file.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: I need help, please help, - 2/5/2008 8:10:45 AM
|
|
 |
|
| |
ebgreen
Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
|
Ok, let's work on some basic trouble shooting. The command that isn't doing what we expect is this: objFSO.CopyFile file.Path, UsbKey So let's see if that command is even being called (since it is inside an If - Then block it may not be) and if it is called exactly what the cammand being executed looks like. The quick and dirty way to do that is to stick a message box in there with the command like this: For Each file in objFolderA.Files If dateDiff("d", file.DateCreated, Date) < 2 Then 'copy file if it's "2 days old" MsgBox "objFSO.CopyFile " & file.Path & ", " & UsbKey objFSO.CopyFile file.Path, UsbKey End If Next
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|