Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Script to print files in multiple locations

I'm looking for a way to search a group of folders for a visio file extension, then automatically print them.
0
XTOSysOps
Asked:
XTOSysOps
  • 4
  • 3
  • 2
1 Solution
 
jkrCommented:
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
 
XTOSysOpsAuthor Commented:
I didn't realize it was in the C+ area....I'll update the question....I really just need a vm script
0
 
XTOSysOpsAuthor Commented:
I meant VB script...not vm script
0
Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

 
jkrCommented:
You are aware that you could simply do that like

start /print c:\path\*.vsd

?
0
 
XTOSysOpsAuthor Commented:
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
 
Bill PrewCommented:
==> 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
 
Bill PrewCommented:
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
 
XTOSysOpsAuthor Commented:
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
 
Bill PrewCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now