Find missing sequential file names

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Data9er
Posts: 1
Joined: 18 Jul 2012 07:45

Find missing sequential file names

#1 Post by Data9er » 18 Jul 2012 07:59

Here is the situation, I have directories that have 10,000 files in each directory named like this:

FilesNAME.XX0000.csv
FilesNAME.XX9999.csv

The Size of the filename itself can change ie:

FilesNAME.XXX0000.csv
FilesNAME.XXX9999.csv

FilesNAME.XXXX0000.csv
FilesNAME.XXXX9999.csv

Where the X's are yet another parent number, but these ones should be ignored anyway.

Regardless though all directories are supposed to have exactly 10,000 files no more and no less. The trouble is some are missing and I need to know which ones are missing. Now I already have a script I use to count the files in sub directories and print the list to file. Then I manually move those folders to an Incomplete folder for further investigation to determine which file names are missing.

I need to come up with a solution that will easily tell me which numbers or file names are missing in the sequence. In my Dream world I would love a script where I can place it inside a parent directory and it would crawl through all the sub directories and print a single file of the missing ones.

It would be nice to not have to tell the script what the beginning part of the file name is, since in theory it should only be looking to see if the last four numbers are in existance from 0000-9999.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find missing sequential file names

#2 Post by foxidrive » 18 Jul 2012 09:30

This should do it from a parent folder. Untested:
It should write the log file in the folder it is executed in.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set "log=%cd%\logfile.txt"
for /f "delims=" %%a in ('dir /ad /b /s') do (
 pushd "%%a"
  for /L %%b in (10000,1,19999) do (
   set a=%%b
   set a=!a:~-4!
   if not exist "*!a!.csv" >>"%log%" echo "%%a - *!a!.csv"
  )
 popd
)

warthog
Posts: 1
Joined: 20 Sep 2012 15:09

Re: Find missing sequential file names

#3 Post by warthog » 20 Sep 2012 15:15

:D thanks foxidrive this is a lifesaver, only thing it's missing was = behind delims I think? (I am a complete novice in batch files but i looked around and noticed people put = there ;)


I was looking for some way to list all missing files in folders containing numbered (sequenced) image files and this is perfect

one thing, what would I have to change to make it work INSIDE a folder (and that it prints logfile inside that same folder?)


I wonder if Data9er solved their problem?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find missing sequential file names

#4 Post by foxidrive » 20 Sep 2012 19:23

warthog wrote:one thing, what would I have to change to make it work INSIDE a folder (and that it prints logfile inside that same folder?)



Just remove the %cd%\ part of set "log=%cd%\logfile.txt"

Thanks for the correction too - I have edited my post above. Glad it was useful for you.

Post Reply