Solved

Looping through a directory and passing a filename to a application

Posted on 2013-06-28
4
219 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 55

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 55

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

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

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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

695 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