We help IT Professionals succeed at work.

need a vbscript or autohokeys macro that would print all the files (which are from different text editing programs incl. non microsoft word processors)in folders and subfolders

Dov_B
Dov_B asked
on
need a vbscript or autohokeys macro that would print all the files (which are from different text editing programs incl. non microsoft word processors)in folders and subfolders
I found on the internet a macro but it omly prints microsoft docs
Comment
Watch Question

Kamaraj SubramanianApplication Support Analyst

Commented:
prints in printer ?
or
prints in output console ?

Author

Commented:
print to a printer
Commented:
A quick way is as follows:

From the command line

dir drive:\path\*.txt,drive:\path\*.log /b /s > c:\filelist.txt

e.g.

To list all files with extension txt and log on drive C:

dir c:\*.txt, c:\*.log /b /s > c:\filelist.txt

the file filelist.txt contains the fully qualified names of all eligible files. Next step - simply read the contents of c:\filelist.txt.

Author

Commented:
the problem is I am printing files made with obscure foreign language wordprocessors not .txt or .html or .htm files
Kamaraj SubramanianApplication Support Analyst
Commented:

Author

Commented:
sorry away so long but there is no print on right click menu
is it possible to simply go into directory after directory and open each file and send a ctrl+p keystroke then {enter} to print then close the file and proceed to the next
Commented:
You should use AutoIT (This is like AutoHotKey, but better in my opinion)

Code would be as follows:


$dir = "c:\TheFolder" ; Directory to search
$search = FileFindFirstFile($dir & "\*.*")

While 1 ; Loop through files
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
	ShellExecute($file) ; Open found file in it's default program.
	sleep(2000) ; Give the program 2 seconds to open
 	Send("^p") ; Send CTRL P
 	Send("!{F4}") ; Send ALT F4
	send("{enter}")
        sleep(1000) ; Give program 1 second to close
WEnd

; Close the search handle
FileClose($search)

Open in new window

Author

Commented:
Terrific!
But for 2 things
1. I remmed out line 10 because it stopped the program from printing after removing this line files printed
2. the loop never ends it just keeps repeatedly printing the files without ever closing them
If you could help me with this issue I would be greatful
Commented:
1. Okay, change the loop as follows:

While 1 ; Loop through files
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
      ShellExecute($file) ; Open found file in it's default program.
      sleep(2000) ; Give the program 2 seconds to open
       Send("^p") ; Send CTRL P
      send("{enter }")
                     sleep(1000) ; Give program one second to print.
       Send("!{F4}") ; Send ALT F4
      send("{enter}")
        sleep(1000) ; Give program 1 second to close
WEnd

2. Line 6 is supposed to exit the loop once all the files have been called, maybe this will work now..

For more accuracy it might be good to add ProcessWait ( "process.exe" ) and ProcessWaitClose ( "process.exe" ) instead of the sleep function. For information on how these functions work, check out the AutoIt Help file, it's very detailed and helpful.

Author

Commented:
Sorry did not get back to you right away thanks to everybody

Explore More ContentExplore courses, solutions, and other research materials related to this topic.