Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

parameters in a DOS .bat file

When I execute the following at the DOS command line, I have no problem:

for /f %k in ('dir/b/s *.xml') do if exist Z:%~pk*.* xcopy %k z:%~pnxk

However, when I put this in a DOS .bat file, it dies on starting at %k. The command line ends up looking like:

for /f ~pk*.* xcopy ~pnxk

and I get this error: xcopy was unexpected at this time.

I suspect this is because the .bat expects a command line parameter in %k, correct? Does anyone know how I can fix this? This a great command provided by billious, but I need to get it working in a batch file.
0
tpatten
Asked:
tpatten
  • 5
1 Solution
 
SteveGTRCommented:
Inside of a batch file use double quotes in for statement.

for /f %%k in ('dir/b/s *.xml') do if exist Z:%%~pk*.* xcopy %%k z:%%~pnxk

Good Luck,
Steve
0
 
SteveGTRCommented:
double quotes = double parans :)
0
 
billiousCommented:
One more time, a little more slowly, SteveGTR

The PERCENTAGE SIGNS need to be doubled before the for-loop control letter if the for-loop is contained in a batch file.

...as mentioned in the last few comments (esp. from pbarette) in

http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20543456.html

IIRC.

...Bill
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
SteveGTRCommented:
Yikes Bill! Thanks :)
0
 
SteveGTRCommented:
My answer with the aid of Bill did the trick. Maybe split the points?
0
 
tpattenAuthor Commented:
This was answered nicely by nillious in the thread he linked to: http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_20543456.html

Unfortunately I posted this question in two different places. The other thread turned out to be the one that took off.
0
 
SteveGTRCommented:
These questions may be related to the same task that you were performing, but they are not the same question...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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