Solved

Looping through a directory and passing a filename to a application

Posted on 2013-06-28
4
212 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 51

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 51

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

21 Experts available now in Live!

Get 1:1 Help Now