Solved

batch file to check for file in all folder

Posted on 2009-07-16
23
308 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
  • 7
  • 6
  • 5
23 Comments
 
LVL 68

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 68

Expert Comment

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

0
 
LVL 68

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 68

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 68

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 68

Expert Comment

by:Qlemo
ID: 24871934
Did you copy the code exactly as-is?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 68

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now