Solved

Script to print files in multiple locations

Posted on 2011-02-18
9
229 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
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
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 55

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 55

Accepted Solution

by:
Bill Prew earned 500 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 55

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 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