Multiple File Counts

Gateway Sx2800
July 27, 2010 at 22:18:02
Specs: Microsoft Windows 7 Home Premium, 2.336 GHz / 4061 MB
Hello,

I need help writing a script file that will provide me with numerous file counts from numerous locations. As part of a reconciliation that I have to do daily on the client I process at work, I have to search multiple client folders for specific items. The folders contain tif images that are all named with a specific DCN.

As an example, let's say the files are stored in C:\Client\SubplanA\072710\Images. The client I process contains multiple subplans, so we have a folder named SubplanA, SubplanB, SubplanC, etc.

Using Windows Explorer, I currently open C:\Clients\SubplanA\Images and search for "*****62". I then record the total number of files found. I then clear the search and search for "*****91," also recording the total number of files found. I then do this for SubplanB, SubplanC, etc.

Is there any way I can have a script file search all of the directores necessary and output the total number of files to a txt file? IE:

SubplanA - 62 - # files
SubplanA - 91 - # files

SubplanB - 62 - # files
SubplanB - 91 - # files

This way, when I perform my reconciliation at the end of the day, I already have all these numbers in one easy location?

I would appreciate any help anyone can give to steer me in the right direction. I've tried piecing together other scripts online but can't get what I need. This would save a ton of time and frustration each day for me. I hope I gave enough information. If you need any clarification, let me know. Thank you!


See More: Multiple File Counts

Report •


#1
July 29, 2010 at 06:47:02
You could probably take advantage of the way those folders
are named with a FOR loop, using the alphabet to whizz
through them and isolate them for counting purposes. What
do the file names look like? Show us a few of them - four
or five - and explain how they need to be targeted in the
search.

Also, you might need to clarify the exact layout of the folder
structure; if there's something variable between SubplanX\
and \Images, that could potentially spoil the 'FOR loop' plan.



Report •

#2
July 29, 2010 at 15:58:03
The files are all .tif images with the actual file name being a document control number. Example: 102096200001.tif, 102096200002.tif, 102096200003.tif, 102096200004.tif, 102096200005.tif, etc. In the few attempts that I've made at doing this, I've just tried to get the file count for all the .tif files in the two different folders being compared.

As for the exact folder layout, there is one of two variables. The company I work for processes HCFA and UB medical claims. Because of that, the date folders in the subplan name has one of the medical claim types attached it to. So, for each subplan we have a MMDDYY_HCFA folder and a MMDDYY_UB folder. Ie:

Subplan A:
C:\Client\SubplanA\MMDDYY_HCFA\Images would need to be compared to C:\Client\SubplanA\MMDDYY_HCFA\Images1
C:\Client\SubplanA\MMDDYY_UB\Images would need to be compared to C:\Client\Subplan\MMDDYY_UB\Images1.

Subplan B:
C:\Client\SubplanB\MMDDYY_HCFA\Images would need to be compared to C:\Client\SubplanA\MMDDYY_HCFA\Images1
C:\Client\SubplanB\MMDDYY_UB\Images would need to be compared to C:\Client\Subplan\MMDDYY_UB\Images1.


Report •

#3
July 29, 2010 at 16:02:48
Mark After this thread is finished i'm am working on something that i need help with. The name is OS i'm making with batch file and matt123. :D

Report •

Related Solutions

#4
July 29, 2010 at 20:46:40
Okay. So, after posting my initial reply to your question, I realized I'm an idiot and that I posted this response which was meant for another project I'm trying to figure out. Please disregard my previous post and forgive me for a stupid momentary lapse of reality.

To truly answer your question...

The files that I am looking to count are all .tif images with the actual file name being a document control number. Example: 102096200001.tif, 102096200002.tif, 102096200003.tif, 102096200004.tif, 102096200005.tif, etc.

The first two digits are the year (10), the next three digits (209) are the Julian date and the next two digits (62) are the two I'm concerned with. I need to count all of the files that contain "62" in the fifth and sixth space of the image name, as well as the total number of files that contain "91" in the fifth and sixth space. The reason these counts are necessary is because the "62" and "91" represent a specific type of claim to the client that needs to be tracked.

Also, as I posted in my original reply, the daily folders do normally have two subfolders but that is not always the case. As an example, sometimes we will only receive a HCFA file for SubplanA, but no UB. Obviously, if we don't receive one of these two files, there is no MMDDYY_HCFA or MMDDYY_UB folder created for that day, whatever the case may be.

So, as an example, let's say I need the counts on the following subplan directories:

Subplan A:
C:\Client\SubplanA\MMDDYY_HCFA\Images
C:\Client\SubplanA\MMDDYY_UB\Images

Subplan B:
C:\Client\SubplanB\MMDDYY_HCFA\Images
C:\Client\SubplanB\MMDDYY_UB\Images

Subplan C*:
C:\Client\SubplanC\MMDDYY_HCFA\Images

*Let's pretend we didn't receive a UB file for this date, however, we may receive one tomorrow.

Sorry for the confusion in posting the wrong reply! Hopefully this provides the information you need. I appreciate any help you can shed on the topic!


Report •

#5
July 30, 2010 at 06:41:27
OK, for now at least, give the following script a try to see
how close it comes to what you need. It just prints the
results to screen at present.

BTW, what level does SubplanX go to - SubplanC, I
imagine?


@echo off

setlocal EnableDelayedExpansion

set ClientFolder=c:\Client

for %%a in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (
  if exist "%ClientFolder%\Subplan%%a\" (
    for %%b in (62,91) do (
      set count=0
      for /f "usebackq delims=" %%c in (`dir /s /b /a:d "%ClientFolder%\Subplan%%a\"`) do (
        set folder=%%~nc
        if /i "!folder!" equ "images" (
          for %%d in ("%%c\?????%%b*") do set /a count+=1
        )
      )
      if !count! neq 0 echo Subplan%%a - %%b - !count! file^(s^)
    )
  )
)



Report •

#6
July 30, 2010 at 06:59:19
Mark After this thread is finished i'm am working on something that i need help with. The name is OS i'm making with batch file and matt123. :D

First thing's first, eh?

<runs for the hills>



Report •

#7
July 31, 2010 at 19:16:34
There's actually 11 different subplans that we have currently. I took your script and gave it a try and it did exactly what I needed it to. I modified the script a bit to point to the correct folders (since our subplans aren't really named SubplanA, etc). and also got the file counts to print to a .txt file that automatically opens after the script is done running.

Thank you so much for the help and for pointing me in the right direction Mark. It's really truly appreciated! :)


Report •

#8
July 31, 2010 at 19:35:56
Mark,

I'm also trying to figure out a second script that maybe you can help me with. Maybe we can take the script above and tweak it a bit?

Before we finish packing up all the data we send to our client, we annotate all of the images with the DCN at the top of the image. This creates an \Images1 folder with what should be, in theory, an exact copy of the \Images folder, except the images are a bit bigger in size due to the annotation.

Is there any way we could get the script to compare the \Images folder to the \Images1 folder and if the file counts are the same, delete the \Images folder? If the counts are different, I'd need it leave both folders so I can compare the two manually.

I added this information here instead of starting a second thread as the information in regards to the setup of the Client and the Subplans and all that is the same.

So... for example...

C:\Client\SubplanA\MMDDYY_HCFA\Images would need to be compared to C:\Client\SubplanA\MMDDYY_HCFA\Images1

C:\Client\SubplanA\MMDDYY_UB\Images would need to be compared to C:\Client\Subplan\MMDDYY_UB\Images1.

Would appreciate any help and insight you can offer on this one too. This would save another decent chunk of time in my day and would be, as always, truly appreciated.


Report •

#9
August 1, 2010 at 07:11:38
I'm not sure if this is exactly what you're looking for but
the code below searches for any subdirs named 'Images'
(starting at %ClientFolder%), then checks to see if there's
a corresponding 'Images1' folder, compares the two
file counts and removes the 'Images' folder if the file
counts are equal. (Actually, it will prompt you to remove
each folder - you'll need to add the /q switch to the rmdir
command for automation.)

for /f "delims=" %%a in ('dir /s /b /a:d "%ClientFolder%"') do (
  set folder=%%~na
  if /i "!folder!" equ "images" if exist "%%a1\" (
    set ImgsCount=0
    set Imgs1Count=0
    for %%f in ("%%a\*") do set /a ImgsCount+=1
    for %%f in ("%%a1\*") do set /a Imgs1Count+=1
    if !ImgsCount! equ !Imgs1Count! rmdir /s "%%a"
  )
)

If it is what you're looking for and you're going to use it
in a separate .bat file, you'll need to copy the first three
non-blank lines from the first script and paste them at
the top of the new script.


Report •

#10
August 1, 2010 at 16:55:43
Mark,

Once again, exactly what I was looking for. I tweaked it just a little bit to get the file counts send to an output file for "auditing" purposes but everything else works great!

Between these two scripts, I've probably really saved about an hours worth of repetitive work every day. That's for the help. I really appreciate it!


Report •

#11
August 3, 2010 at 03:53:00
Between these two scripts, I've probably really saved about an hours worth of repetitive work every day.

Sounds good! Thanks for the update.


Report •

#12
August 3, 2010 at 04:56:03
One more small question. I didn't even think about this until I took the script to work yesterday and ran it. For the image compare folder, is there any way to exclude folders that are included in a DONE folder?

For each Subplan, we have the following folder setups:
C:\
-Client
-SubplanA
-MMDDYY_HCFA
-MMDDYY_UB
-DONE

Once today's files are fully processed, they'll be moved to the DONE folder tomorrow. The images and images1 folder will be compared before they are moved, however, so in theory there is no need to look in the DONE subfolder.

If there's a way to fit that small tweak in that would be perfect. If not, it'll just take the script a little extra to run since it'll be looking through extra directories, but that's not a big issue.

Thanks again!


Report •

#13
August 3, 2010 at 07:16:38
Are you saying that, if an 'Images' folder is found, you
want to check that the next higher level folder is not a
folder named 'DONE' and skip if it is?



Report •

#14
August 3, 2010 at 08:14:44
Mark,

That's correct. The current process checks the images and images1 folder the following day. For example, this morning at work I checked all of yesterday's images/images1 counts. After deleting the images folders, yesterday's files are moved to the DONE folder. Each subplan has a DONE folder that has multiple previous days in them. The DONE folders are burned to DVD once they reach 4 GB. For some subplans this takes a week. Others can take a month or so to reach the 4GB size.

Since the script is checking %ClientFolder%, which we set to C:\Client, it's checking all of the subdirectories including all the DONE folders.

This isn't really that big of an issue if the "fix" isn't an easy one. The script is currently working perfectly. It just takes a while due to having to look through those extra DONE directories. I was just wondering if there was any way to skip the DONE folders since, in theory, there should be no images/images1 to compare.

As always, I appreciate the help!


Report •

#15
August 3, 2010 at 08:39:02
See if this does it - it's pretty much the same code as in
Response #9 with an extra check added...

for /f "delims=" %%a in ('dir /s /b /a:d "%ClientFolder%"') do (
  set folder=%%~na
  if /i "!folder!" equ "images" if exist "%%a1\" (
    set HigherFolder=%%~pa
    for /f "delims=" %%b in ("!HigherFolder:~0,-1!") do set HigherFolder=%%~nb
    if /i "!HigherFolder!" neq "done" (
      set ImgsCount=0
      set Imgs1Count=0
      for %%f in ("%%a\*") do set /a ImgsCount+=1
      for %%f in ("%%a1\*") do set /a Imgs1Count+=1
      if !ImgsCount! equ !Imgs1Count! rmdir /s "%%a"
    )
  )
)


Report •

#16
August 3, 2010 at 09:29:02
I just gave that one a shot but it's still going through the DONE folder. I created a copy of an images1 folder in one of yesterday's files, renamed it to images, and it still was deleted.

Report •

#17
August 3, 2010 at 12:08:10
Firstly, check to see that there's no unwanted chars in
the script - especially spaces at the end of lines which you
can't normally see. If that doesn't change anything, show
us an actual path, or at least something that accurately
shows the relatiionship between the Images folder and the
DONE folder.


Report •

Ask Question