Solved

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

Posted on 2014-11-20
4
230 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 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 56

Expert Comment

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

~bp
0
 
LVL 56

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

630 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