Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

use variable file name in directory and process that file in batch command

Posted on 2013-01-25
4
Medium Priority
?
469 Views
Last Modified: 2013-01-25
I want to look at a directory and process (print) the random TIFF files that appear. The problem is that names are not uniform, they could be just about anything in a tiff extension.

So how do I parse the contents of a directory into a variable and process that variable? There may be more than one TIFF file waiting to be processed, I can loop it until there is nothing else to process.

I would be using the
     rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\faxes\faxmessage.tiff" "\\corporate\printername" "" ""
comamnd to print the tiff files.

Thanks,
Chuck
0
Comment
Question by:fcbc
  • 3
4 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38819154
The for command is what you want.  You can either iterate down files using plain for

@echo off
cd /d C:\faxes
for %%a in (*.tif?) do (
  rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "%%~fa" "\\corporate\printername"
  echo Do something else with the file "%%~a", full name is "%%~fa"
)

or read a directory listing such as

@echo off
for /f %%a in ('dir /b /a-d *.tif?') do (
   echo Filename is %%~a
)

I presume you might want to do a move command after the print too?

The %%a is abritary and case sensitive, use %%T or %%t or whatever if you prefer.
the ~ means remove any " " around the filename, in case it has spaces etc. it is better to remove then add yourself.
You can add qualifiers to the %%~a to get (f = full filename, n=name, x=extension etc.)

for /? explains more.

Steve
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 38819160
I used *.tif? btw in case you have .tif or .tiff files.

Steve
0
 

Author Comment

by:fcbc
ID: 38819604
wow - WORKS FANTASTIC.

If anyone else tries this, just have a minor correction to above:
rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "%%~fa" "" ""

you will need those extra 2 sets of quotes at the end of the line.

Thank you for your quick response!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38819629
no problem for is very powerful command and used a lot around here... for /? set /? has lots of useful stuff, or ask here if needed.

stevev
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

876 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