Solved

batch file to check for file in all folder

Posted on 2009-07-16
23
314 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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