Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script to print files in multiple locations

Posted on 2011-02-18
9
Medium Priority
?
243 Views
Last Modified: 2012-05-11
I'm looking for a way to search a group of folders for a visio file extension, then automatically print them.
0
Comment
Question by:XTOSysOps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 34927890
Since you posted that in the C++ area, here's the code that would do that recursively for a given directory - just call that like

printapp.exe *.vsd c:\example\path
#include <windows.h>
#include <stdio.h>
 
void HandleFile ( LPCSTR pPath, WIN32_FIND_DATA* pw32fd);
void WalkTree ( char* pszPath,  char*   pszBase);
void main ( int argc, char** argv)
{
    if  (   argc    !=  3)  return;
 
    WalkTree ( *( argv + 1), *(argv + 2));
}
 
void WalkTree ( char* pszPath,  char*   pszBase)
{
WIN32_FIND_DATA w32fd;
HANDLE hFind;
DWORD dwAtt;
char acPath [ MAX_PATH];
char acBase [ MAX_PATH];
 
printf  (   "WalkTree():\tcalled with '%s' '%s'\n",   pszPath,    pszBase);
 
if ( '.' == * (pszPath + lstrlen ( pszPath) - 1))
                return;
 
if  (   pszBase)
    sprintf (   acPath, "%s\\%s",   pszBase,    pszPath);
else
    lstrcpy ( acPath, pszPath);
 
printf ( "path is %s\n",    acPath);
lstrcpy ( acBase, acPath);
 
dwAtt = GetFileAttributes ( acPath);
 
if ( 0xffffffff == dwAtt)
{
 // error ...
}
 
if ( FILE_ATTRIBUTE_DIRECTORY & dwAtt)
{
    if  (   '\\'    ==  acPath  [   lstrlen (   acPath) -   1])
            lstrcat (   acPath, "*.*");
     else
            lstrcat (   acPath, "\\*.*");
 
    printf ( "path is now %s\n",    acPath);
}
 
 
hFind = FindFirstFile ( acPath, &w32fd);
 
if ( INVALID_HANDLE_VALUE == hFind)
{
 // error
 
printf ( "ERROR %d\n",  GetLastError    ());
 
return;
}
 
// recurse if directory...
if ( FILE_ATTRIBUTE_DIRECTORY == w32fd.dwFileAttributes)
{
 
     WalkTree ( w32fd.cFileName,    acBase);
}
else
 HandleFile ( pszPath, &w32fd);
 
while ( FindNextFile ( hFind, &w32fd))
{
    // recurse if directory...
    if ( FILE_ATTRIBUTE_DIRECTORY == w32fd.dwFileAttributes)
    {
 
     WalkTree ( w32fd.cFileName,    acBase);
    }
    else
      HandleFile ( &w32fd);
}
 
if ( ERROR_NO_MORE_FILES != GetLastError())
{
 // error
}
FindClose ( hFind);
}
 
void HandleFile (LPCSTR pszPath, WIN32_FIND_DATA* pw32fd)
{
  char acPath[MAX_PATH];
  sprintf(acPath,"%s\\%s",pszPath, pw32fd->cFileName);

  ShellExecute(NULL,"print",acPath,NULL,NULL,SW_SHOW);
}

Open in new window

0
 

Author Comment

by:XTOSysOps
ID: 34927930
I didn't realize it was in the C+ area....I'll update the question....I really just need a vm script
0
 

Author Comment

by:XTOSysOps
ID: 34927961
I meant VB script...not vm script
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 86

Expert Comment

by:jkr
ID: 34928028
You are aware that you could simply do that like

start /print c:\path\*.vsd

?
0
 

Author Comment

by:XTOSysOps
ID: 34929348
I'm very green when it comes to any type of script writing....so your saying open notepad type "start /print c:\share\folder\*.vsd" save as a .bat and it will search all subdirectories for a .vsd file and send it to the default printer?
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 34931079
==> I'm looking for a way to search a group of folders for a visio file extension, then automatically
==> print them.

Are the group of folders all subfolders of a common parent, or in some other way related?

~bp
0
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 34931194
If all the visio files are in subfolders under a single parent, then this small BAT file will get the job done. Save this as a BAT file, adjust the SET statements near the top to include the location of your visio.exe program, the starting folder to search for visio files underneath, and the name of the printer you wantto send the printouts to.

@echo off
set BaseDir=c:\temp
set VisioExe=C:\Program Files\Microsoft Office\Office14\VISIO.EXE
set PrinterName=Duplex Printer
for /R "%BaseDir%" %%V in (*.vsd) do "%VisioExe%" /pt "%%~V","%PrinterName%"

Open in new window

~bp
0
 

Author Comment

by:XTOSysOps
ID: 34933160
Thanks BillPrew....I'm getting much closer, right now it will search the base directory and open visio, but when it tries to open the file it keeps putting the printer name as part of the file path so the file doesn't actually open...For Example "This file could not be found (D:\My Documents\drawing.vsd,printer1)"
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 34934811
Are you using the script I provided, or a modified version, or just from the command line?  Can you share the exact command you are executing. Also, what version of Visio are you running, I tried a command line like this on my system and it works as expected:

"C:\Program Files\Microsoft Office\Office14\VISIO.EXE" /pt "c:\temp\test.vsd","Duplex Printer"

Open in new window

~bp
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question