Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i combine two scripts 1

Status
Not open for further replies.
Apr 11, 2003
105
US
I have a project where i have to print 30,000 indivdual files in 800 folders under a subfolder C:\00
How would i write a scrip to do this task or combine the follwing two scripts. The Top Script renames any file from *.1 to *.doc in any folder on a root, and the second scrip prints all of the files in a folder. If i could combine these two, it would server the purpuse

Code:
And what about this ?
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\work")

Sub ShowSubFolders(Folder)
For Each objFile In Folder.Files
    If Right(objFile.Name, 2) = ".1" Then
        objFile.Name = Left(objFile.Name, Len(objFile.Name)-1) & "doc"
    End If

Next
End Sub

Code:
TargetFolder = "C:\00\" 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items

For i = 0 to colItems.Count - 1
    colItems.Item(i).InvokeVerbEx("Print")
Next
 
Convert the 2nd script to a function or a sub with TargetFolder as argument.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello DanClark86!

Try something like this..
Code:
For Each objFile In Folder.Files
    If Right(objFile.Name, 2) = ".1" Then
        objFile.Name = Left(objFile.Name, Len(objFile.Name)-1) & "doc"
        objFile.InvokeVerbEx("Print")
    End If

Next
Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
I am still not too strong on scripting, i don't understand.
 
Wait, sorry, the script I suggested doesn't work. Go with PHV's suggestion. (I guess I should test my code before I post it huh :) ).

Thanks!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
snotmare, you confuse FileSystemObject and Shell.Application ...
 
Snotmare, Thanks for your help any sugestions are great at this time,

PHV, I dont know how to Convert the 2nd script to a function or a sub with TargetFolder as argument. Can you explain a little more?
 
PHV is suggesting something like this...
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\work")

Sub ShowSubFolders(Folder)
For Each objFile In Folder.Files
    If Right(objFile.Name, 2) = ".1" Then
        objFile.Name = Left(objFile.Name, Len(objFile.Name)-1) & "doc"
    End If

Next
Call subPrint(Folder)
End Sub 

Sub subPrint(TargetFolder)
   Set objShell = CreateObject("Shell.Application")
   Set objFolder = objShell.Namespace(TargetFolder) 
   Set colItems = objFolder.Items

   For i = 0 to colItems.Count - 1
      colItems.Item(i).InvokeVerbEx("Print")
   Next
End Sub

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
So if i wanted to eliminate the renaming of the files then i could do something like this:

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\00")

Sub ShowSubFolders(Folder)
For Each objFile In Folder.Files
    
Next
Call subPrint(Folder)
End Sub 

Sub subPrint(TargetFolder)
   Set objShell = CreateObject("Shell.Application")
   Set objFolder = objShell.Namespace(TargetFolder) 
   Set colItems = objFolder.Items

   For i = 0 to colItems.Count - 1
      colItems.Item(i).InvokeVerbEx("Print")
   Next
End Sub
 
If you don't want to rename your files, then all you need is the second script that you provided in your first post. Keep in mind that this only prints out the files in your root folder. If you want to include all sub folders, then you'll need to do something like this...
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\00")

Sub ShowSubFolders(Folder)
   Call subPrint(Folder)
   For Each objFolder In Folder.SubFolders
      call ShowSubFolders(objFolderFolder)
   Next
End Sub 

Sub subPrint(TargetFolder)
   Set objShell = CreateObject("Shell.Application")
   Set objFolder = objShell.Namespace(TargetFolder) 
   Set colItems = objFolder.Items

   For i = 0 to colItems.Count - 1
      colItems.Item(i).InvokeVerbEx("Print")
   Next
End Sub

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
When i run that script i get the following error:

WSH
Script: C:\...\file.vbs
line: 14
Char: 4
Error Object Required: 'objfolder'
Code: 80a01a8
source: Microsoft VBScript Runtime Error
 
I plaed the line
TargetFolder = "C:\00\"
in the script just before line 14 and then i get the error:

WSH
Script: C:\...\file.vbs
line: 6
Char: 4
Error Object Required: 'objfolder'
Code: 80a01a8
source: Microsoft VBScript Runtime Error
 
sorry scrath that last post. The error is

WSH
Script: C:\...\file.vbs
line: 6
Char: 4
Error Object Required: 'Folder'
Code: 80a01a8
source: Microsoft VBScript Runtime Error
 
The error might be caused by a type-o in the red line below...
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\00")

Sub ShowSubFolders(Folder)
   Call subPrint(Folder)
   For Each objFolder In Folder.SubFolders
      [red]call ShowSubFolders(objFolder)[/red]
   Next
End Sub 

Sub subPrint(TargetFolder)
   Set objShell = CreateObject("Shell.Application")
   Set objFolder = objShell.Namespace(TargetFolder) 
   Set colItems = objFolder.Items

   For i = 0 to colItems.Count - 1
      colItems.Item(i).InvokeVerbEx("Print")
   Next
End Sub

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
i am still getting that error.
WSH
Script: C:\...\file.vbs
line: 6
Char: 4
Error Object Required: 'Folder'
Code: 80a01a8
source: Microsoft VBScript Runtime Error

Where dose the Folder object come from?
 
I got the code to work if I added a backslash in the red line...
Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("H:\Ferguson\HTML\Frames")

Sub ShowSubFolders(Folder)
   Call subPrint(Folder)
   For Each objFolder In Folder.SubFolders
      call ShowSubFolders(objFolder)
   Next
End Sub 

Sub subPrint(TargetFolder)
   Set objShell = CreateObject("Shell.Application")
   [red]Set objFolder = objShell.Namespace(TargetFolder & "\") [/red]
   Set colItems = objFolder.Items

   For i = 0 to colItems.Count - 1
      colItems.Item(i).InvokeVerbEx("Print")
   Next
End Sub

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
It was PHV's idea, but thanks.

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top