• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

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.AtEndOfStream

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

Open in new window

0
CCG3
Asked:
CCG3
  • 7
  • 6
  • 2
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
What version of the windows scripting host (wscript.exe) is installed on W7 * XP? They are probably different.
0
 
Daz_1234Commented:
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.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
du.exe is not standard on Windows7 either, on Windows7 the script is running.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Daz_1234Commented:
==> 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.
0
 
CCG3Author Commented:
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?
0
 
Daz_1234Commented:
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:

du.exe \\failingXPcomp\share\folder

Open in new window


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.
0
 
CCG3Author Commented:
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.
0
 
Daz_1234Commented:
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:

'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

Open in new window

Note the new lines 25 - 26

Regards,
Daz.
0
 
CCG3Author Commented:
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?
0
 
Daz_1234Commented:
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):

'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

Open in new window



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"

Open in new window

Regards,
Daz
0
 
CCG3Author Commented:
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?
0
 
CCG3Author Commented:
It could be the space in Documents and Settings as well.
0
 
Daz_1234Commented:
Well the modification I just made should cater for the spaces.  

Can you, from a cmd prompt, just do this to confirm the folder actually exists (obviously replace username):

dir "\\Vaness-Desk\c$\Documents and Settings\username"

... if it doesn't then just:

dir "\\Vaness-Desk\c$\Documents and Settings" to see if the 'username' folder exists.

Regards,
Daz.
0
 
CCG3Author Commented:
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.
0
 
Daz_1234Commented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now