CCG3
asked on
Problem reading XP folders...
I am running a script that looks at certain folder locations on specified PCs and tells me the folder size. It works fine for Win 7 PCs but is failing when it looks at XP machines.
I have a attached the code here. It seems to run fine until it gets to the line that says:
Do While Not objExec.StdOut.AtEndOfStre am
And at that point it does not move into that area, it just moves to the next item in the Folderlist.xls file.
I can't see anything wrong with it and I thought it worked before. I know it works on Win 7 PC's but not on Win XP.
thanks for any help you can provide.
I have a attached the code here. It seems to run fine until it gets to the line that says:
Do While Not objExec.StdOut.AtEndOfStre
And at that point it does not move into that area, it just moves to the next item in the Folderlist.xls file.
I can't see anything wrong with it and I thought it worked before. I know it works on Win 7 PC's but not on Win XP.
thanks for any help you can provide.
'On Error Resume Next
inputfile="C:\folderlist.xls" 'path of excel file
outputfile="C:\output.txt" 'path of output file to be written
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(inputfile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outputfile=objfso.OpenTextFile(outputfile,2)
intRow = 1
Do Until objExcel.Cells(intRow,1).Value = ""
strcomputer=Trim(objExcel.Cells(intRow, 1).Value)
folder=Trim(objExcel.Cells(intRow, 2).Value)
folder_path="\\"&strcomputer&"\"& folder
WScript.Echo folder_path
Set objShell = CreateObject("Wscript.Shell")
command = "du.exe " & folder_path
Set objExec = objShell.Exec(Command)
WScript.Echo "TEST"
Do While Not objExec.StdOut.AtEndOfStream
WScript.Echo "TEST"
strText = Trim(objExec.StdOut.ReadLine())
' Test or display strText
WScript.Echo strText
If InStr(strText,"Size: ")>0 Then
fsize=Replace(strText,"Size: ","")
fsize=Replace(fsize," bytes","")
fsizedbl=CDbl(fsize)
WScript.Echo "File size " & fsizedbl
'outputfile.WriteLine strcomputer & "," & folder & "," & fsize
outputfile.WriteLine strcomputer & "," & folder & "," & Replace(fsize, ",", "") '
Exit Do
End If
Loop
intRow = intRow + 1
Loop
outputfile.Close
objExcel.Quit
What version of the windows scripting host (wscript.exe) is installed on W7 * XP? They are probably different.
du.exe is not standard in Windows XP Pro, so you'd need to install it on your XP computer before running this script. Is this the case?
Regards,
Daz.
Regards,
Daz.
du.exe is not standard on Windows7 either, on Windows7 the script is running.
==> Yes you are right, so obviously du.exe has been installed on the Win 7 computer. I was not going to make the same assumption about the XP one.
Daz.
Daz.
ASKER
Thanks for the replies. I am running this on my machine and going out and looking at these machines remotely so it should not matter what what version of wscript they have or if they have DU or not. Right?
Ok I see now. I apologise, I read it as the script would not run on an XP computer, not that it fails when connecting to XP computers. Sorry about that I should read more carefully.
What happens when you run it from a command window manually with a path to an XP client computer?
So open a command window (cmd.exe) and type in straight:
What is the output then? I expect you to see an error, which is not captured by the normal StdOut stream, but by StdErr stream instead, which would explain why the script errors, because StdOut is empty.
Regards,
Daz.
What happens when you run it from a command window manually with a path to an XP client computer?
So open a command window (cmd.exe) and type in straight:
du.exe \\failingXPcomp\share\folder
What is the output then? I expect you to see an error, which is not captured by the normal StdOut stream, but by StdErr stream instead, which would explain why the script errors, because StdOut is empty.
Regards,
Daz.
ASKER
I will try it from Cmd line today. No error and no output. It gets to that line and jumps out of the loop. No idea why.
You would not get the error from the du.exe command (if there was one), because you are not capturing StdErr. This amended version will do that:
Regards,
Daz.
'On Error Resume Next
inputfile="C:\folderlist.xls" 'path of excel file
outputfile="C:\output.txt" 'path of output file to be written
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(inputfile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outputfile=objfso.OpenTextFile(outputfile,2)
intRow = 1
Do Until objExcel.Cells(intRow,1).Value = ""
strcomputer=Trim(objExcel.Cells(intRow, 1).Value)
folder=Trim(objExcel.Cells(intRow, 2).Value)
folder_path="\\"&strcomputer&"\"& folder
WScript.Echo folder_path
Set objShell = CreateObject("Wscript.Shell")
command = "du.exe " & folder_path
Set objExec = objShell.Exec(Command)
WScript.Echo "TEST"
If Not objExec.StdErr.AtEndOfStream Then
MsgBox "STDERR: " & Command & vbCrlf & objExec.StdErr.ReadAll, vbExclamation + vbSystemModal, "ERROR Found"
End If
Do While Not objExec.StdOut.AtEndOfStream
WScript.Echo "TEST"
strText = Trim(objExec.StdOut.ReadLine())
' Test or display strText
WScript.Echo strText
If InStr(strText,"Size: ")>0 Then
fsize=Replace(strText,"Size: ","")
fsize=Replace(fsize," bytes","")
fsizedbl=CDbl(fsize)
WScript.Echo "File size " & fsizedbl
'outputfile.WriteLine strcomputer & "," & folder & "," & fsize
outputfile.WriteLine strcomputer & "," & folder & "," & Replace(fsize, ",", "") '
Exit Do
End If
Loop
intRow = intRow + 1
Loop
outputfile.Close
objExcel.Quit
Note the new lines 25 - 26Regards,
Daz.
ASKER
ok when I run the same script with your changes I do get an error. No idea what it means though. I think it is a syntax error with the du.exe
STDERR: du.exe \\Vaness-Desk\c$\Documents and Settings\username\My Documents
the path is correct (I plugged in the username and took out the actual).
is that helpful at all?
STDERR: du.exe \\Vaness-Desk\c$\Documents
the path is correct (I plugged in the username and took out the actual).
is that helpful at all?
I would have hoped to see an error message in there as well.
It could be that the space in 'My Documents' is causing a problem. Try (amended line 19):
But what happens when you run it direct in a cmd window? (obviously fixing the username bit again):
Daz
It could be that the space in 'My Documents' is causing a problem. Try (amended line 19):
'On Error Resume Next
inputfile="C:\folderlist.xls" 'path of excel file
outputfile="C:\output.txt" 'path of output file to be written
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(inputfile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outputfile=objfso.OpenTextFile(outputfile,2)
intRow = 1
Do Until objExcel.Cells(intRow,1).Value = ""
strcomputer=Trim(objExcel.Cells(intRow, 1).Value)
folder=Trim(objExcel.Cells(intRow, 2).Value)
folder_path="\\"&strcomputer&"\"& folder
WScript.Echo folder_path
Set objShell = CreateObject("Wscript.Shell")
command = "du.exe """ & folder_path & """"
Set objExec = objShell.Exec(Command)
WScript.Echo "TEST"
If Not objExec.StdErr.AtEndOfStream Then
MsgBox "STDERR: " & Command & vbCrlf & objExec.StdErr.ReadAll, vbExclamation + vbSystemModal, "ERROR Found"
End If
Do While Not objExec.StdOut.AtEndOfStream
WScript.Echo "TEST"
strText = Trim(objExec.StdOut.ReadLine())
' Test or display strText
WScript.Echo strText
If InStr(strText,"Size: ")>0 Then
fsize=Replace(strText,"Size: ","")
fsize=Replace(fsize," bytes","")
fsizedbl=CDbl(fsize)
WScript.Echo "File size " & fsizedbl
'outputfile.WriteLine strcomputer & "," & folder & "," & fsize
outputfile.WriteLine strcomputer & "," & folder & "," & Replace(fsize, ",", "") '
Exit Do
End If
Loop
intRow = intRow + 1
Loop
outputfile.Close
objExcel.Quit
But what happens when you run it direct in a cmd window? (obviously fixing the username bit again):
du.exe "\\Vaness-Desk\c$\Documents and Settings\username\My Documents"
Regards,Daz
ASKER
I ran it with the modified and just the single line and I get an error that says no matching files were found. I agree I think it could be the space in My Documents.
I also ran it with a value of My%20%Documents instead and got the same error.
any ideas on how to get around that?
I also ran it with a value of My%20%Documents instead and got the same error.
any ideas on how to get around that?
ASKER
It could be the space in Documents and Settings as well.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh how I loathe typos!!! It just so happens that both of the examples I grabbed as test subjects had typos, both with computer name.
thanks for your help! I did learn more about troubleshoot this code! Sorry to waste your time.
thanks for your help! I did learn more about troubleshoot this code! Sorry to waste your time.
Not at all - the troubleshooting steps are as valid to spot typos in your own code / input as they are to find other errors.
Glad you found it anyway!
Daz.
Glad you found it anyway!
Daz.