processing same files with same prefix

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ehabaziz2001
Posts: 2
Joined: 17 Jan 2014 20:39

processing same files with same prefix

#1 Post by ehabaziz2001 » 17 Jan 2014 20:51

My dir.lst as like this :
*************************
wady0_Hold.out.new
wady0_Post.out.new
wady2_Hold.out.new
wady2_Post.out.new
wady3_Post.out.new
wady4_Hold.out.new

For missing pairs I am doing this :

Code: Select all

dir /b %folder%\*.out.new > dir1.lst 

@echo off
for /f "tokens=1,* delims=_" %%a in (dir1.lst) do (
   echo %%a
   ::for missing pairs
   if not exist %folder%\%%a_Post.out.new copy nul %folder%\%%a_Hold.out.new
   if not exist %folder%\%%a_Hold.out.new copy nul %folder%\%%a_Post.out.new
   
   pause ""
)

But I can see that the new created files are created over the old ones with the same names . That is against the syntax written above ????

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: processing same files with same prefix

#2 Post by foxidrive » 17 Jan 2014 23:35

Explain what you are trying to do.
If the code doesn't work and there is no explanation then it can be extremely difficult to know what you are trying to do.

ehabaziz2001
Posts: 2
Joined: 17 Jan 2014 20:39

Re: processing same files with same prefix

#3 Post by ehabaziz2001 » 18 Jan 2014 05:33

If one single file of each pair is not created , I need to create it empty .
If post file is not created for a pair I need to create it empty (nul). If hold file is not created , I need to create it empty (nul).

For missing pairs I am doing this :

Code: Select all

dir /b %folder%\*.out.new > dir1.lst 

@echo off
for /f "tokens=1,* delims=_" %%a in (dir1.lst) do (
   echo %%a
   ::for missing pairs
   if not exist %folder%\%%a_Post.out.new copy nul %folder%\%%a_Hold.out.new
   if not exist %folder%\%%a_Hold.out.new copy nul %folder%\%%a_Post.out.new
   
   pause ""
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: processing same files with same prefix

#4 Post by foxidrive » 18 Jan 2014 05:51

Try this.

Code: Select all

@echo off
for %%a in (*_Hold.out.new) do for /f "tokens=1,* delims=_" %%b in ("%%a") do if not exist "%%b_Post.out.new" type nul >"%%b_Post.out.new"
for %%a in (*_Post.out.new) do for /f "tokens=1,* delims=_" %%b in ("%%a") do if not exist "%%b_Hold.out.new" type nul >"%%b_Hold.out.new"

Post Reply