Solved

Multiple commands inside a DO LOOP

Posted on 2004-10-04
2
689 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 125 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

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

718 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