• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1958
  • Last Modified:

Pass variable file path to batch file?

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
KPS2007
Asked:
KPS2007
  • 3
  • 2
1 Solution
 
SteveGTRCommented:
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
 
MSE-dwellsCommented:
SteveGTR: are  you loving' this new 'code-snippett' feature or what? ;0)
0
 
SteveGTRCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
KPS2007Author Commented:
This snippet helped me get it running the way I like, thanks!
0
 
MSE-dwellsCommented:
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
 
SteveGTRCommented:
That's a good idea. Because if one user can do it you know that more users can.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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