Solved

Pass variable file path to batch file?

Posted on 2007-11-15
6
1,927 Views
Last Modified: 2012-08-13
I need some help passing a variable to a batch file, specifically the path of a file.  My batch file looks something like this:
net use lpt2:  serverdesignjet
copy /b filename.plt lpt2
net use lpt2: /delete

It would be great if users could just drag a .plt on to this batch file and have it run.  Currently the have to move the .plt file and rename it, which as you can imagine isn't very fast.

Thanks!
0
Comment
Question by:KPS2007
  • 3
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 100 total points
Comment Utility
Could do this:
@echo off
 

setlocal
 

set fileName=%~1
 

if "%~1"=="" set /p fileName=Please enter file name to processing: 

if "%fileName%"=="" echo Processing aborted&goto :EOF

if not exist "%fileName%" echo File does not exist&pause&goto :EOF
 

net use lpt2:  serverdesignjet

copy /b "%fileName%"  lpt2

net use lpt2: /delete 

Open in new window

0
 
LVL 9

Expert Comment

by:MSE-dwells
Comment Utility
SteveGTR: are  you loving' this new 'code-snippett' feature or what? ;0)
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
Yes I am.

Although it does appear that some users attempt to paste the line numbers with the code. You can do it by starting the drag at the numbers. One user insisted it was a bug and asked if I would repost the code in a message.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:KPS2007
Comment Utility
This snippet helped me get it running the way I like, thanks!
0
 
LVL 9

Expert Comment

by:MSE-dwells
Comment Utility
ROFL, that cracks me up ... and so you can!  Perhaps EE could consider rendering them in a way that they can't become part of copy/paste op (or even provide a download this as a "TEXT" file button).
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
That's a good idea. Because if one user can do it you know that more users can.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 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

7 Experts available now in Live!

Get 1:1 Help Now