Solved

bat file to scan sub directories to check for set of files

Posted on 2014-11-20
4
214 Views
Last Modified: 2014-12-03
Hi,
I am trying to search all subdirectories in a folder C:\Stage, for a set of files.
File names differ based on the source they come form, for example, load1.csv, load 14.csv, load 21.csv.
So I need to look for files based on load*.csv, import*.csv, etc.

I got the below for QLemo, but need to modify the hardcoded file names to wldcard ones.

Thanks!


@echo off
set reqfiles=load1.csv load2.csv load3.csv
set numfiles=3
pushd .
for /D %%D in (C:\Stage) do (
  cd /D %%D
  for /F %%C in ('dir %reqfiles" /b ^| find /c /v ""') do if %%C equ %numfile% echo %%D is ok
)
popd
0
Comment
Question by:chetan1981
  • 2
4 Comments
 

Author Comment

by:chetan1981
ID: 40455047
Also just to add, there Directories are on a UNC path, dong a pushd to a UNC path errors out, any workarouund.
Really appreciate any help I can get, I have no expertise in DOS.

Thanks.
0
 
LVL 25

Accepted Solution

by:
SStory earned 250 total points
ID: 40455146
Using cd with UNC will cause errors -not supported.
However using pushd instead of cd will create a temporary virtual drive to that UNC.

Example:
rem Creates a temporary drive letter if UNC and changes to that drive
pushd %%D
  for /F %%C in ('dir %reqfiles" /b ^| find /c /v ""') do if %%C equ %numfile% echo %%D is ok
rem pops back to location before the push
popd

This will solve your UNC issue.
I don't know what you're end goal is. Just listing files?

if so why not
dir /b /s load*.csv;dir /b /s import*.csv?
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40456532
What do you want to do when you find the files?

~bp
0
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
ID: 40456556
Okay, not knowing exactly what you are after, here's a thought.  This approach assumes you want to have at least one file in each file group, but we can adjust if needed for different results desired.

@echo off
setlocal

REM Define folder and files to search
set BaseDir=\\server\share\dir1
set FindList="load*.csv","import*.csv"

REM Initialize count of files searched for, and files found
set FindCount=0
set FoundCount=0

REM Loop through each file group
for %%A in (%FileList%) do (
  REM Count how many groups searched
  set /a FindCount+=1
  
  REM Count the number of matching files in this group
  for /f %B in ('dir "%BaseDir%\%%~A" /a-d /b /s ^| find /v "" /c') do (
    REM If we found any files, add to count of groups with files in them
    if %%B GTR 0 (
      set /a FoundCount+=1
    )
  )
)

REM Compare count of groups searched and count of groups with files found in them
if %FoundCount% EQU %FindCount% (
  echo Found at least one file in all groups searched
) else (
  echo Missing files for at least one group searched
)

Open in new window

~bp
0

Featured Post

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

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now