1

I have multiple ascii files like Total-0100.dat and want to batch process using an executable in another directory.

In short,

  1. I have multiple files with incremnet of 100 or 1000 e.g. Total-001000.dat, Total-02000.dat up to Total-600000.dat. they are in one drive/drictory say A. say: A:\work.

  2. I want to batch process these file by using the executable in my program files of C drive. say: C:\Program Files\Program\run.exe

  3. Finally I store these converted files to another directory. say: A:\work1 I have an initial code, that is not working. I need help in this regard.

I am working in Windows 7...

@echo off
for /l %%i in (1,1,400000) do
"C:\Program Files\Program\run.exe" Total-%%i.dat

1 Answer 1

3

You forgot to add '(' and ')' after do, write it like this:

@echo off
for /l %%i in (1,1,400000) do (
"C:\Program Files\Program\run.exe" Total-%%i.dat )

or on one line without brackets:

@echo off
for /l %%i in (1,1,400000) do "C:\Program Files\Program\run.exe" Total-%%i.dat

To run this batch file (which you saved for example in c:\test\script.bat) from another directory, simply change your current directory in cmd to A:\work1, open cmd and type:

C:\Windows\system32> a:
A:\> cd work1
A:\work1> c:\test\script.bat

or copy the script to A:\work1\script.bat and run your script from there:

C:\Windows\system32> a:
A:\> cd work1
A:\work1> script.bat

An alternative is to open the directory A:\work1 in Explorer and hold down SHIFT + right-click in the right pane in an empty white are and choose Open command window here from the menu.

or use the full path in your script:

@echo off
for /l %%i in (1,1,400000) do (
"C:\Program Files\Program\run.exe" A:\work1\Total-%%i.dat )
2
  • thanks. It is working. How to set and use different directories as I mention in my question?
    – TheCoder
    May 2, 2016 at 14:12
  • See my updated answer for changing the directory.
    – rda
    May 2, 2016 at 17:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .