Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple commands inside a DO LOOP

Posted on 2004-10-04
2
Medium Priority
?
701 Views
Last Modified: 2008-02-26
I'm trying to write a batch file that writes another file that is based on two things: 1) A list of files 2) a Count

I want the batch file to list files of a certain type (.jpg in this intsnace) and then write those files to a temporary file. Then, line by line, read in those file names and write them to another file with an incremented number.

ie.

Batch start

dir *.jpg /b > files.txt  
                       - Writes a list of jpg files to files .txt

for /F "DELIMS=" %%F IN (files.txt) DO (Echo %%F %count >> %1.txt)
                       - Writes a line to my file (given by %1) containing a file name (from DIR command earlier) and  a count.

I can't see how to facilitate a "Count" variable in this DO loop as I don't know how to do multiple commends inside the paraentheses.

I guess I need to use "SET /A COUNT=COUNT+1", but I can't see where or how as I only seem to be able to do one thing in the DO() bit.

Thanks, flaxius
0
Comment
Question by:flaxius
[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 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 12217237
Give this a try:

@echo off

setlocal enabledelayedexpansion

dir *.jpg /b > files.txt  

set count=0

for /F "DELIMS=" %%F IN (files.txt) DO (
  set /a count+=1
  Echo %%F !count! >> %1.txt
)

The key to getting this working is the enabledelayedexpansion and the use of the exclamation (!) around the environment variable in the do loop. Check out setlocal /? for more information.

Good Luck,
Steve
0
 

Author Comment

by:flaxius
ID: 12217653
Thanks Steve, just the job!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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