Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 12th, 2006, 09:49 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,867 mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Weeks 15 h 20 m 54 sec
Reputation Power: 1762
Error running VBScript (.VBS) File

I have a .VBS file that when run on my local machine, has no problems. Now that it has been moved to the production server, I get an error. The script takes all same files (first 6 characters of a file name) within a directory/sub directory structure and creates a batch file to combine these text files into one file.
vb Code:
Original - vb Code
  1.  
  2. Option Explicit
  3.    
  4. Dim strPath, strArchive, strDisallow, strCombine
  5. Dim oFSO, oFolder, oFiles, oPath, sFolder
  6. Dim x, s
  7. Dim rs
  8. Dim oNew, strFile, strBatch, strBat
  9. Dim newFolder, nFolder
  10. Dim wShell
  11.  
  12. Const adVarChar = 200
  13. strDisallow = "|archive|combine|"
  14.  
  15. Dim argObj, varFile, varExtension, varLength
  16. Set argObj = WScript.Arguments
  17.  
  18. 'First parameter
  19. varFile = lcase(trim(argObj(0)))
  20. varLength = Len(trim(argObj(0)))
  21. 'Second parameter
  22. varExtension = lcase(trim(argObj(1)))
  23. 'MsgBox varFile & " - " & varExtension
  24.  
  25. main()
  26.    
  27. Function main()
  28.  
  29.     Const directory = "C:\Inetpub\wwwroot\test"
  30.     Const archive = "C:\Inetpub\wwwroot\test\archive\"
  31.     Const combined = "C:\Inetpub\wwwroot\test\combine\"
  32.  
  33.     strPath = directory
  34.     strArchive = archive
  35.     strCombine = combined
  36.    
  37.     ' Create our FSO
  38.     Set oFSO = CreateObject("Scripting.FileSystemObject")
  39.     ' Get a handle on our folder
  40.     Set oFolder = oFSO.GetFolder(strPath)
  41.    
  42.     set rs = CreateObject("ADODB.Recordset")
  43.     rs.Fields.Append "name", adVarChar, 8000
  44.     rs.Fields.Append "location", adVarChar, 8000
  45.     rs.Open
  46.    
  47.     oPath = oFolder.Path
  48.     Set oFiles = oFolder.Files
  49.     For Each x In oFiles
  50.         If LCase(Left(x.Name,varLength)) = varFile Then
  51.             If lcase(Right(x.Name,3)) = varExtension Then
  52.                 rs.AddNew
  53.                 rs.Fields("location").Value = oPath & "\" & x.Name & " + "
  54.                 rs.Fields("name").Value = x.Name
  55.             End If
  56.         End If
  57.     Next
  58.    
  59.     getSubFolders oFSO.GetFolder(strPath)
  60.  
  61.     'Remove File & Folder objects      
  62.     Set oFiles = Nothing
  63.     Set oFolder = Nothing
  64.    
  65.     ' Now we can sort our data:
  66.     ' Sort ascending by name
  67.     With rs
  68.         .Sort = "name ASC"
  69.         Do While Not .EOF
  70.             strBatch = strBatch & .Fields("location").Value
  71.             strFile = strFile & .Fields("name").Value & ", "
  72.             .MoveNext
  73.         Loop
  74.     end With
  75.    
  76.     strBatch = left(strBatch,Len(strBatch)-3)
  77.     strBat = varFile & ".bat"
  78.    
  79.     'Create batchfile needed to combine files
  80.     Set oNew = oFSO.CreateTextFile(strPath & "\" & strBat)
  81.     oNew.WriteLine("echo off")
  82.     oNew.WriteLine("REM combines the individual files into one large file")
  83.     oNew.WriteLine("copy /b " & strBatch &  " " & strCombine & varFile & ".DAT")
  84.     oNew.WriteLine("REM pause")
  85.     oNew.WriteLine("echo on")
  86.     oNew.Close
  87.     'Remove new batch file object
  88.     Set oNew=Nothing
  89.    
  90.     strBatch = ""
  91.     newFolder = strArchive & varFile
  92.     If Not oFSO.FolderExists(newFolder) Then
  93.      Set nFolder = oFSO.CreateFolder(newFolder)
  94.     End If
  95.     'Remove the new folder object
  96.     Set nFolder = Nothing
  97.    
  98.     'Run batchfile to combine the files
  99.     Dim runBat
  100.     runBat = strPath & "\" & strBat
  101.     'MsgBox runBat
  102.     set wShell = CreateObject("WScript.Shell")
  103.     wshell.run runBat, 0, True
  104.     set wShell = Nothing
  105.    
  106.     'Move files to archive directory
  107.     With rs
  108.         .MoveFirst
  109.         Do While Not .EOF
  110.             strBatch = Left(.Fields("location").Value,Len(.Fields("location").Value)-3)
  111.             If oFSO.FileExists(strBatch) Then
  112.                 oFSO.MoveFile strBatch, newFolder & "\"
  113.                 'MsgBox strBatch & " " & newFolder
  114.          End If
  115.       .MoveNext
  116.      Loop
  117.     End With 
  118.    
  119.     'Close/remove ADO Recordset object
  120.     rs.Close
  121.     Set rs = Nothing
  122.     'Remove FileSystemObject
  123.     Set oFSO = Nothing 
  124. End Function   
  125.  
  126. Sub getSubFolders(Folder)
  127.     For Each sFolder In Folder.SubFolders
  128.         If InStr(LCase(strDisallow),"|" & LCase(sFolder.Name) & "|") = 0 Then
  129.             oPath = sFolder.Path
  130.             Set oFolder = oFSO.GetFolder(oPath)
  131.             Set oFiles = oFolder.Files
  132.             For Each x In oFiles
  133.                 If LCase(Left(x.Name,varLength)) = varFile Then
  134.                     If LCase(Right(x.Name,3)) = varExtension Then
  135.                         rs.AddNew
  136.                         rs.Fields("location").Value = oPath & "\" & x.Name & " + "
  137.                         rs.Fields("name").Value = x.Name
  138.                     End If
  139.                 End If
  140.             Next
  141.         End If
  142.         getSubFolders oFolder
  143.     Next
  144. End Sub

it bombs out on line 127: For Each sFolder In Folder.SubFolders with the following error.
Microsoft VBScript runtime error: Out of Memory: 'Folder.SubFolders'.

Any clue as to what this can mean. Again, it runs fine on my machine, where it was written, but will not run on the production server.

Thanks.
__________________
Come JOIN the party!!!

Quote of the Month:
Retirement: Because you've given so much of yourself to the company that you don't have anything left we can use.

Questions to Ponder:
What do you do when you see an endangered animal eating an endangered plant?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright© 2008 sbenj69

Reply With Quote
  #2  
Old December 12th, 2006, 10:02 AM
chapman10s's Avatar
chapman10s chapman10s is offline
**Wanted Wizard**
ASP Free God (5000 - 5499 posts)
 
Join Date: Apr 2006
Location: Who knows...
Posts: 5,410 chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)chapman10s User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 12139 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 4 Days 12 h 36 m
Reputation Power: 1331
Send a message via AIM to chapman10s Send a message via MSN to chapman10s
Mehere--

Usually that is referring to an infinite loop somewhere? Since the code in the vbs script searches the list of parent sources until the end, there is a stack overflow (out of memory) which eventually occurs because there is no end. Just a hunch i guess....
__________________
I would rather know than not know at all...



Reply With Quote
  #3  
Old December 12th, 2006, 10:05 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,867 mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 4 Weeks 15 h 20 m 54 sec
Reputation Power: 1762
i kinda went that way, but the directory it runs in has 7 subdirectories and no directories under those subs. when i ran it on my machine, i had 15 directories, with at least 2-3 subdirectories under each one of those and it runs with no problems. i'm stumped, to say the least.

Reply With Quote
  #4  
Old December 12th, 2006, 06:14 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,635 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1Folding Points: 373781 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 h 55 m 37 sec
Reputation Power: 1902
--moved to the brand new Windows Scripting forum.

well, first of all I noticed the Archive and Combined are
part of the main folder - it might be better idea to have
them outside, for example:
Code:
	Const directory = "C:\Inetpub\wwwroot\test"
	Const archive = "C:\Inetpub\wwwroot\archive\"
	Const combined = "C:\Inetpub\wwwroot\combine\"

if still no luck, Debug for the Rescue:
Code:
Sub getSubFolders(Folder)
    MsgBox("getSubFolders called for: " & Folder.Name)   
    For Each sFolder In Folder.SubFolders
        ...

it would at least verify whether it's infinite loop or not...
Comments on this post
mehere agrees: thanks

Reply With Quote
  #5  
Old December 13th, 2006, 07:29 PM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,867 mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)mehere User rank is General 12nd Grade (Above 100000 Reputation Level)