?
Solved

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

Posted on 2014-11-20
4
Medium Priority
?
233 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
[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
  • 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 1000 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 57

Expert Comment

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

~bp
0
 
LVL 57

Assisted Solution

by:Bill Prew
Bill Prew earned 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 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