Jump to content

Display missing files out of groups.


Recommended Posts

Howdy all.

I would like to create a script that will scan a folder, see how many "filename-001" (FC) files there are, and look for highest number in the "filename-***-001" column (SC). Then display what files are missing in the second column.

Below there are 2 groups of files. The first 5 files within the first column (FC) being -001-. There are also 5 files with the (SC) number starting at -001- and going to -005-. The second group of 5 files within the first column (FC) being -002-. There are also 5 files with the (SC) number starting at -001 and going to -005.

FC= First column.
SC= Second column.
         FC   SC
filename-001-001
filename-001-002
filename-001-003
filename-001-004
filename-001-005

filename-002-001
filename-002-002
filename-002-003
filename-002-004
filename-002-005


Below are the same two groups of files. Missing is file 3 of group 1. Also missing is 4 of group 2.

         FC   SC
filename-001-001
filename-001-002

filename-001-004
filename-001-005

filename-002-001
filename-002-002
filename-002-003

filename-002-005

What I would like to do is display what files are missing.

Any suggestions on where to start. I am motivated to make this work, as it will save me a lot of time and energy :x

Thanx for any input.

Link to comment
Share on other sites

Not a trivial matter but here is my solution:

#include <Array.au3>
#include <file.au3>

Dim $FileArray, $BigArray[1][3], $MidArray, $temp
$FileArray = _FileListToArray("c:\test")
ReDim $BigArray[$FileArray[0]][3]                   ;will hold all the file names split by "-"
Dim $MidArray[$FileArray[0]]                    ;will hold the mid number (FC)
For $i = 1 To $FileArray[0]
    $temp = StringSplit($FileArray[$i], "-")
    For $j = 1 To $temp[0]
        $BigArray[$i-1][$j-1] = $temp[$j]               ;put the value in the big array
        If $j = 2 Then $MidArray[$i-1] = $temp[$j]  ;put middle string in $MidArray
    Next
Next
;_ArrayDisplay($BigArray, "Big")
;_ArrayDisplay($MidArray, "Mid")
Dim $UniqueArray, $tempArray, $ResultArray
$UniqueArray = _ArrayUnique($MidArray)              ;get unique mid-strings
;_ArrayDisplay($UniqueArray, "Unique")
For $i = 1 To UBound($UniqueArray)-1
    $tempArray = _ArrayFindAll($BigArray, $UniqueArray[$i], 0, 0, 0, 0, 1)  ;get all array indexes for the same mid-string
    ;_ArrayDisplay($tempArray, "Find"&$UniqueArray[$i])
    Dim $ResultArray[UBound($tempArray)][3]
    For $j = 0 To UBound($tempArray) - 1            ;build a temporary array to hold these entries
        $ResultArray[$j][0] = $BigArray[$tempArray[$j]][0]
        $ResultArray[$j][1] = $BigArray[$tempArray[$j]][1]
        $ResultArray[$j][2] = $BigArray[$tempArray[$j]][2]
    Next
    _ArraySort($ResultArray, 0, 0, 0, 2)
    For $k = Number($ResultArray[0][2]) To Number($ResultArray[UBound($ResultArray)-1][2])
        If _ArraySearch($ResultArray, $k, 0, 0, 0, 0, 1, 2) <> -1 Then
            ContinueLoop
        Else
            MsgBox(0, "Missing File", $ResultArray[0][0]&"-"&$ResultArray[0][1]&"-"&StringFormat("%03d", $k))
        EndIf
    Next
Next

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

@enaiman

You sir are a God at this.

It works perfectly.

I expected a few pointers to get started with. After looking at the code, I'm sure glad I asked first :x

A couple things I will need to add to "polish" this. Like a "browse to folder". Could you throw a couple pointers on how to output all the missing files to a text file. I don't want you to do the work, but give me a few examples.

Thank you for taking the time to help me with this.

Link to comment
Share on other sites

@enaiman

Yup "MsgBox with FileWriteLine" worked great.

I'm having a heck of a time trying to get "browse to folder" working, This is the code where I am stuck at. The last line is where the error is coming from. Any ideas what I am doing wrong. I have a feeling it has something to do with the "Dim" function.

Thanx again for your help.

#include <Array.au3>
#include <file.au3>

Dim $FileArray, $BigArray[1][3], $MidArray, $temp
; $FileArray = _FileListToArray("F:\filename-here\052")
$fold = FileSelectFolder("Choose a folder.", "")
$FileArray =_FileListToArray($fold,"*.",2)
ReDim $BigArray[$FileArray[0]][3]                   ;will hold all the file names split by "-"
Link to comment
Share on other sites

$FileArray =_FileListToArray($fold,"*.",1)

If you use Option 2 - it will return folders only (no files).

$iFlag=0(Default) Return both files and folders

$iFlag=1 Return files only

$iFlag=2 Return Folders only

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

You need to select the folder where the files are located - if there are no files, you will get errors.

It doesn't search subfolders.

At this stage there is no error control implemented in the code. That needs to be done at some point.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...