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
Solved

Script to print files in multiple locations

Posted on 2011-02-18
9
226 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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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 53

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 53

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 53

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

790 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