Alternative Nation
Go Back   Alternative Nation > Lounge > Computers & Technology > Web Dev & Programming

Notices

Reply
 
Thread Tools Rate Thread
Old 21st February 2008, 10:32am   #1
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Script to print all files in folder and subfolders

Can you write a piece of code or a script to print all the files in a folder and its sub folders? I can write a vbs script to print all files in one folder but I have no idea how to include sub folders.

The script I've been using is shown below.

Any help?

TargetFolder = "EXAMPLE FOLDER"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem in colItems
objItem.InvokeVerbEx("Print")
Next
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 21st February 2008, 10:40am   #2
Forever Waiting.
 
johnnie walker's Avatar
 
Join Date: Nov 2004
Location: Glasgow
Posts: 4,050
Blog Entries: 73
Images: 199
johnnie walker serenades with sweet wordsjohnnie walker serenades with sweet wordsjohnnie walker serenades with sweet wordsjohnnie walker serenades with sweet wordsjohnnie walker serenades with sweet words
Send a message via MSN to johnnie walker Send a message via Skype™ to johnnie walker
Re: Script to print all files in folder and subfolders

This sounds like what you need: (The second part)
http://www.microsoft.com/technet/scr...4/hey1020.mspx

The basic idea is that you recursively loop through each of the folders in the top folder and print the files in there.
__________________

Mario Kart Friend Code: 3351-4224-7274
Wii Code: 8516 7078 6265 0398
johnnie walker is offline   Reply With Quote
Old 21st February 2008, 11:23am   #3
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Re: Script to print all files in folder and subfolders

I've had a play with that but for some reason it hates the line

Set colItems = objFolder.Items

When I change it to

Set colItems = objFolder.files

It will display the name of each file on the screen but not print them.

Here's my current script

Quote:
Set objFSO = CreateObject("Scripting.FileSystemObject")
TargetFolder = "IingaporeCaley CDR drawings and slidesCDR PACKAGE- 13-2-08IROV"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem in colItems
objItem.InvokeVerbEx("Print")
Next
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set objFolder = objFSO.GetFolder(TargetFolder)
Wscript.Echo objFolder.Path
Set colItems = objFolder.items
For Each objItem in colItems
objItem.InvokeVerbEx("Print")
Next
Wscript.Echo
ShowSubfolders objFSO.GetFolder(objFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.items
For Each objItem in colItems
objItem.InvokeVerbEx("Print")
Next
Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 21st February 2008, 1:48pm   #4
MANLEGEND
SuperMod
 
PapaZeb's Avatar
 
Join Date: Sep 2002
Location: Las Vegas, NV
Posts: 26,618
Images: 582
PapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny tech
Send a message via AIM to PapaZeb Send a message via MSN to PapaZeb Send a message via Yahoo to PapaZeb Send a message via Skype™ to PapaZeb
Re: Script to print all files in folder and subfolders

with WMI/VBS it's a pain in the ass (but since I'm dead at work, I might as well give it a shot when I go to work today)

If you just need it enumerated and VBS isn't a requirement, how about

Start -> Run -> CMD

dir /s NAMEOFDIRECTORY > c:/directory.txt

Open c:/directory.txt in notepad or whatever. Hit PRINT.

I'd use
dir /s /b NAME > c:/directory.txt
since it'll just spit back filenames
__________________
PapaZeb is offline   Reply With Quote
Old 21st February 2008, 2:01pm   #5
MANLEGEND
SuperMod
 
PapaZeb's Avatar
 
Join Date: Sep 2002
Location: Las Vegas, NV
Posts: 26,618
Images: 582
PapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny tech
Send a message via AIM to PapaZeb Send a message via MSN to PapaZeb Send a message via Yahoo to PapaZeb Send a message via Skype™ to PapaZeb
Re: Script to print all files in folder and subfolders

Yeah...you were going about it the hard way

Code:
const ForAppending = 8
textFilePath = "C:test.txt" 
set objFSO = createobject("Scripting.FileSystemObject")
set objTextFile = objFSO.opentextfile(textFilePath,ForAppending)
strFolder = "C:ringtones"

set objFSO = createobject("Scripting.FileSystemObject")

GetFiles strFolder

sub GetFiles(byval strDirectory)
	set objFolder = objFSO.GetFolder(strDirectory)
	for each objFile in objFolder.Files
		objTextFile.WriteLine objFile.Path 
	next	
	for each objFolder in objFolder.SubFolders
		GetFiles objFolder.Path
	next
end sub
objTextFile.Close
Things you could add - check that the text file to be written to exists, create if not. Error checking, file attributes, pass in text file or target folder as arguments..that sorta thing.

Unless you want to go about this in a totally tarded method of sending things to a printer?
__________________
PapaZeb is offline   Reply With Quote
Old 21st February 2008, 2:05pm   #6
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Re: Script to print all files in folder and subfolders

Nah i don't want to print a list of all files in a folder and sub folder, I want to print all the files (.dwg AutoCAD files).

Or am I getting what's written in that code all wrong?
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 21st February 2008, 2:10pm   #7
MANLEGEND
SuperMod
 
PapaZeb's Avatar
 
Join Date: Sep 2002
Location: Las Vegas, NV
Posts: 26,618
Images: 582
PapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny tech
Send a message via AIM to PapaZeb Send a message via MSN to PapaZeb Send a message via Yahoo to PapaZeb Send a message via Skype™ to PapaZeb
Re: Script to print all files in folder and subfolders

My mistake - looked at code more than the question (and all you kept doing was enumerating the files)

VBS isn't the right tool to print out a bunch of CAD files. About the best it can do is open the file and pop open the Print dialog box in my experience

Which CAD application using?

And a quick run around the google shows automated autocad printing generally requiring a program add-on..if I were more familiar with CAD terminology I might be able to drill down on a search to pull out something useful.
__________________

Last edited by PapaZeb; 21st February 2008 at 2:10pm. Reason: Automerged Doublepost
PapaZeb is offline   Reply With Quote
Old 21st February 2008, 2:40pm   #8
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Re: Script to print all files in folder and subfolders

I'll do it the hard way.

Cheers though.
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 21st February 2008, 2:46pm   #9
MANLEGEND
SuperMod
 
PapaZeb's Avatar
 
Join Date: Sep 2002
Location: Las Vegas, NV
Posts: 26,618
Images: 582
PapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny techPapaZeb wants shiny tech
Send a message via AIM to PapaZeb Send a message via MSN to PapaZeb Send a message via Yahoo to PapaZeb Send a message via Skype™ to PapaZeb
Re: Script to print all files in folder and subfolders

Actually....if the first script you put up will print the CAD files in a single folder just fine, try (change the strFolder= line, obviously)

set objFSO = createobject("Scripting.FileSystemObject")
strFolder = "C:\ringtones"
GetFiles strFolder
sub GetFiles(byval strDirectory)
set objFolder = objFSO.GetFolder(strDirectory)
for each objFile in objFolder.Files
objItem.InvokeVerbEx("Print")
next
for each objFolder in objFolder.SubFolders
GetFiles objFolder.Path
next
end sub
__________________

Last edited by PapaZeb; 21st February 2008 at 2:48pm. Reason: Removed CODE tags, kept stripping backslashes
PapaZeb is offline   Reply With Quote
Old 21st February 2008, 2:54pm   #10
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Re: Script to print all files in folder and subfolders

It does yeah. Cheers for that. Already done most of them though.

Actually it wont recognise the objitem hwen you try and include the subfolders but recongizes it fine when you try and apply it to one level.

I don't get it.
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 21st February 2008, 7:02pm   #11
Changed Man V4
 
Join Date: May 2002
Location: Breaking into H
Posts: 32,061
Images: 303
Zooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than Hoody
Send a message via MSN to Zooropa
Re: Script to print all files in folder and subfolders

edit: sack that, doesnt work
__________________
You just lost The Game
Zooropa is offline   Reply With Quote
Old 21st February 2008, 7:46pm   #12
Changed Man V4
 
Join Date: May 2002
Location: Breaking into H
Posts: 32,061
Images: 303
Zooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than Hoody
Send a message via MSN to Zooropa
Re: Script to print all files in folder and subfolders

strDirectory = "E:\Code\SQL"


Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strDirectory)
Set colItems = objFolder.Items
For Each objItem in colItems
objItem.InvokeVerbEx("Edit")
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objMainFolder = objFSO.GetFolder(strDirectory)
Set colSubfolders = objMainFolder.Subfolders
For Each objSubfolder in colSubfolders
strFolder = objSubfolder.Path
GetFiles strFolder
Next

sub GetFiles(byval strDirectory)
Set objWeeFolder = objShell.Namespace(strDirectory)
Set colWeeItems = objWeeFolder.Items
For Each objWeeItem in colWeeItems
objWeeItem.InvokeVerbEx("Edit")
Next
end sub

This works!

Maybe a bit clumsy, but I was able to go through to a subfolder and loop through the items in that.
It currently only goes down 1 level, but could be changed to loop through other subfolders.

I just sepnt 45 minutes on that, and enjoyed every minute of it.
Work from work, although VBS is fucking old school.
Oh, and obviously change "Edit" to "Print"
__________________
You just lost The Game

Last edited by Zooropa; 21st February 2008 at 7:48pm. Reason: Automerged Doublepost
Zooropa is offline   Reply With Quote
Old 22nd February 2008, 1:44pm   #13
Punisher
Moderator
 
Jushin Liger's Avatar
 
Join Date: Sep 2002
Location: Glasgow
Posts: 8,849
Images: 70
Jushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the buildingJushin Liger has left the building
Send a message via MSN to Jushin Liger
Re: Script to print all files in folder and subfolders

Cool, that's handy.
__________________
No matter where you go, you are what you are player
And you can try to change but that's just the top layer
Man, you was who you was 'fore you got here


Jushin Liger is offline   Reply With Quote
Old 22nd February 2008, 6:39pm   #14
Changed Man V4
 
Join Date: May 2002
Location: Breaking into H
Posts: 32,061
Images: 303
Zooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than HoodyZooropa is better than Hoody
Send a message via MSN to Zooropa
Re: Script to print all files in folder and subfolders

Big Hoody was telling me on MSN he had to copy a file into 900 folders the other day.

"Could I have used VBS for that?"

"Aye."
__________________
You just lost The Game
Zooropa is offline   Reply With Quote
Old 22nd February 2008, 7:34pm   #15
Twiztid Juggalo
Moderator
 
Mos Def's Avatar
 
Join Date: Jul 2002
Location: 1-800-Crenshaw
Posts: 19,673
Images: 44
Mos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heatMos Def can take the heat
Send a message via MSN to Mos Def Send a message via Yahoo to Mos Def
Re: Script to print all files in folder and subfolders

It nearly killed me.
__________________
'CAUSE MUTHAFUCKAS ARE BORED


h00dy_p@hotmail.com

Quote:
shut up hoody, just because it isn't your thing doesn't make it rubbish
Aye it does.
Mos Def is offline   Reply With Quote
Reply

Bookmarks
Digg del.icio.us StumbleUpon Google

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Sin 



 Bamboo





Powered by vBadvanced CMPS v3.0.0
Advertisement
   



All times are GMT +0. The time now is 8:00pm.

Forums Directory
Copyright 2000-2008, Alternative Nation

SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Page generated in 0.81024 seconds with 15 queries