NoobieAutoitUser Posted January 17, 2011 Share Posted January 17, 2011 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 Thanx for any input. Link to comment Share on other sites More sharing options...
enaiman Posted January 17, 2011 Share Posted January 17, 2011 Not a trivial matter but here is my solution: expandcollapse popup#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 More sharing options...
NoobieAutoitUser Posted January 17, 2011 Author Share Posted January 17, 2011 @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 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 More sharing options...
enaiman Posted January 17, 2011 Share Posted January 17, 2011 Simply replace MsgBox with FileWriteLine If you give a full path to your text file, FileWriteLine will open and close the file automatically. 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 More sharing options...
NoobieAutoitUser Posted January 17, 2011 Author Share Posted January 17, 2011 @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 More sharing options...
enaiman Posted January 17, 2011 Share Posted January 17, 2011 $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 More sharing options...
NoobieAutoitUser Posted January 17, 2011 Author Share Posted January 17, 2011 ReDim $BigArray[$FileArray[0]][3] Error ^ I changed the line (sorry I need to go to bed) I'm getting the same error messge. I dont have a clue what to do with "redim". Link to comment Share on other sites More sharing options...
enaiman Posted January 17, 2011 Share Posted January 17, 2011 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 More sharing options...
NoobieAutoitUser Posted January 17, 2011 Author Share Posted January 17, 2011 (edited) I figured out what the problem was. $FileArray =_FileListToArray($fold,"*.",1) I removed the "." after the "*". Now everything works right. Thanks again for your help. This script is going to save me hours of time. EDIT: Fixed a typo. Edited January 17, 2011 by NoobieAutoitUser Link to comment Share on other sites More sharing options...
NoobieAutoitUser Posted January 18, 2011 Author Share Posted January 18, 2011 (edited) Dood, This thing is fantastic. It took just a hair over a minute to scan 13,823 @ 3.06 GB worth of files. THanx a billion again!!!! EDIT: Typo Edited January 18, 2011 by NoobieAutoitUser Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now