Solved

Looping through a directory and passing a filename to a application

Posted on 2013-06-28
4
214 Views
Last Modified: 2013-07-23
Experts,

I have a directory full of files and I need to pass their filename to an application in Command Prompt, how could I accomplish this?  I seen forfile used, but can't get the syntax down, any help would be appreciated.

The application's syntax looks like C:\Myfolder\myapp.exe s:C:\locationoffile\myfile.xml

Where the switch for s: should be the path for each file.
0
Comment
Question by:lm1189
  • 2
4 Comments
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
ID: 39285796
Try this:

@echo off
set BaseDir=C:\locationoffile
set RunPgm=C:\Myfolder\myapp.exe
for %%A in ("%BaseDir%\*.xml") do (
  "%RunPgm%" s:%%~A
)

Open in new window

~bp
0
 

Author Comment

by:lm1189
ID: 39290043
While it makes sense, and it looks like it should work, I get unable to Parse Command Line.  Any idea?
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39291869
Can you copy exactly the file you are running and post it here please.

~bp
0
 
LVL 17

Accepted Solution

by:
Lior Karasenti earned 250 total points
ID: 39294879
Put the script in the directory in which you want to list the files:
@echo off
for /f "tokens=*" %%? in ('dir /a-d /b') do C:\Myfolder\myapp.exe s:%%~f?
goto :eof

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

17 Experts available now in Live!

Get 1:1 Help Now