?
Solved

Looping through a directory and passing a filename to a application

Posted on 2013-06-28
4
Medium Priority
?
220 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 56

Assisted Solution

by:Bill Prew
Bill Prew earned 750 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 56

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 750 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

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.

Question has a verified solution.

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

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

771 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