Solved

Script to print files in multiple locations

Posted on 2011-02-18
9
222 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
 
LVL 86

Expert Comment

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

start /print c:\path\*.vsd

?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 51

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 51

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 51

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now