Solved

Looping through a directory and passing a filename to a application

Posted on 2013-06-28
4
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 54

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 54

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xcopy loop 13 67
Batch/VBScript : Disable Windows tasks 7 45
Scan Network and Export Reg value to single file 2 50
WMIC Output Formatting 1 49
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…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…

726 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