Solved

batch file to check for file in all folder

Posted on 2009-07-16
23
311 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 69

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 69

Expert Comment

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

0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 69

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 69

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 69

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 69

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 69

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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