Solved

batch file to check for file in all folder

Posted on 2009-07-16
23
313 Views
Last Modified: 2012-05-07
How can I check if "results.txt" exist in all sub folder under "C:\folder\results\"?
0
Comment
Question by:CalmSoul
[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
  • 7
  • 6
  • 5
23 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 24870912
I.e. each subfolder has to contain results.txt, and you want to see which one does not?
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 24870961
Yes
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24870965
for /F "tokens=*" %%F in ('dir /a:d') do if not exist %%F\results.txt echo %%F

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 70

Expert Comment

by:Qlemo
ID: 24870987
Should give the starting folder, too, and do all folders, of course:

for /F "tokens=*" %%F in ('dir /a:d /s /b C:\folder\results\') do if not exist %%F\results.txt echo %%F
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 24871106
So what is the output? I only want those folders list which doesn't contain results.txt
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24871442
Try it ... It should do exactly that. If you want to try it on command line (outside of a batch file), you have to replace %% by %.

0
 
LVL 70

Accepted Solution

by:
Qlemo earned 250 total points
ID: 24871455
On command line, you should use this form, less output:

@for /F "tokens=*" %F in ('dir /a:d /s /b C:\folder\results\') do @if not exist %F\results.txt echo %F


0
 
LVL 5

Author Comment

by:CalmSoul
ID: 24871903
getting message "d" was unexpected at this time
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24871934
Did you copy the code exactly as-is?
0
 
LVL 16

Assisted Solution

by:t0t0
t0t0 earned 250 total points
ID: 24872096
Apologies for adding one more possible solution

@echo off
DEL %~n0.log 2>NUL

FOR /F "TOKENS=*" %%a IN ('DIR /AD /B /S c:\folder\results\*') DO (
   IF NOT EXIST %%a\results.txt (
      ECHO %%a >>%~n0.log
   )
)

IF EXIST %~n0.log (
   ECHO Some folders did not contain Results.txt. See %~n0.log for details.
)
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24872209
Sorry??? That solution is just an expansion of mine.
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 24881251
sorry i got confuse... I should have split points
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24881403
CalmSoul

I'm quite happy for you to summon a moderator to re-open this question providing you ACCEPT my code as the solution (as you have done above) and award Qlemo ASSISTED in the solution. I will agree to a 50/50 split in points. Finally, a grade 'A' would ensure we get the 'full' points awarded.

To summon a moderator: click on "Request Attention" (bottom right near red icon of your question above)
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24886599
In my previous post, I stated quite clearly I was happy for you to re-open this question and award points to Qlemo however, I did stipulate 3 conditions. These were:

(1) you "ACCEPT" my code as the solution, and award "ASSISTED" in the solution to Qlemo

(2) a 50/50 split in points

(3) a grade 'A'

While you satisfied  (2) and (3), you did NOT "ACCEPT" my code as the solution. I have been awarded points on the basis that I only "ASSISTED" in the solution.

This is unfair as it was in good faith that I agreed for you re-open this question.
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 24886699
Ohh you want accepted and his assited?

If that is the case reopen the question I will do that... I am rookie is accpet multiple solutions
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24886717
CalmSoul

When you close a question you are given the option of accepting multiple comments as your solution.

The first comment you should click on is the one which you select as your ACCEPTED solution then after, you select others as ASSISTED in that solution.

I fear, because Qlemo's solution appears chronologically before mine, you clicked on that one first then proceeded to click on mine and this is why the ACCEPTEDB and ASSISTED are in the order as they are.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24887570
Sorry, didn't realise off topic was remmoved due to not refreshing my browser before posting.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24887595
WhackAMod

Why won't you allow me to make general comments to Qlemo? I'm not breaking any rules. I'm not going off on a rant. I'm not using unacceptable tone. Please allow me the freedom to post messages. If I am doing something wrong them please say so otherwise it appears you are spiting me.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…

738 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