Jump to content
Sign in to follow this  
Haagimus

Script used to work and stopped after reformat

Recommended Posts

Haagimus

Okay so here's the problem, myself and few of the 10 lb brains on this site developed a script that I was trying to create that would basically query my entire server, add all files into an array, query every file to check if it was created more than 14 days from current time, remove all entries older than 14 days from the array, then finally output all the remaining files into a text file with the creation date attached.

This script is beautiful and worked like a charm, until my server had a HDD failure and general WHS failure. Since I have rebuilt and reformatted the system and placed all backup up files back into the server the script no longer works as advertised. I get the following error and will post the code below.

New Files TXT output.au3 (21) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$FilteredFiles[$FilteredFiles[0][0] + 1][0] = $Time[2] & StringUpper(_DateToMonth($Time[1], 1)) & $Time[0]
^ ERROR

and here is the code itself:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Comment=Thanks to Melba23 for helping with the multi dimensional array issues
#AutoIt3Wrapper_Res_Description=Scans a directory recursively and searches for any files newer that 14 days and lists them in a text file.
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <file.au3>
#include "RecFileListToArray.au3"

Global $NowTime = _NowCalc(), $Time ;Gets the current date and time
Global $Folder = "B:\ServerFolders"
;Global $Folder = FileSelectFolder("Select", "") ;Testing only
Global $Files = _RecFileListToArray($Folder, "*", 0, 1, 0, 1, "*.db;*.pst;*.rwz;*.ini;*.jpg;*.dat;*.tmp;*.configdat;*.cc;*.txt", "Client Computer Backups;Documents;Misc Files;Networking Stuff;Private;Pictures;School;Users") ;Adds the files from the folder selected to an array
Global $FilteredFiles[$Files[0]][2]

Local $File = (@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt")

For $iFile = 1 To $Files[0]
$Time = FileGetTime($Folder & "\" & $Files[$iFile], 0)

If _DateDiff("D", $Time[0] & "/" & $Time[1] & "/" & $Time[2] & " " & $Time[3] & ":" & $Time[4] & ":" & $Time[5], $NowTime) < 14 Then ;created more than 14 days ago
$FilteredFiles[$FilteredFiles[0][0] + 1][0] = $Time[2] & StringUpper(_DateToMonth($Time[1], 1)) & $Time[0]
$FilteredFiles[$FilteredFiles[0][0] + 1][1] = $Files[$iFile]

$FilteredFiles[0][0] += 1
EndIf ;The above formula tells the program to find anything in the array that is older than 14 days and discard it
Next

ReDim $FilteredFiles[$FilteredFiles[0][0] + 1][2] ;Resize array

FileOpen($File, 2)
If $File = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

FileWriteLine($File, "Updated on " & $NowTime & @CRLF & @CRLF) ;Add header to text file with time it was updated
FileWriteLine($File, "This file is automatically generated everyday at midnight and noon" & @CRLF & @CRLF)
_FileWriteFromArray($File, $FilteredFiles, 2, 0, " < Creation --- Location > ") ;Write array to the text file
FileClose($File)

FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Anime", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Homemade Programs", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Installers", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Kids Movies", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Music", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\New Downloads", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Recorded TV", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Videos", 1)
FileCopy(@ScriptDir & "\00-READ ME FIRST - NEWEST FILES LISTED WITHIN.txt", $Folder & "\Workout Programs", 1)

Exit

Any 10 lb brains out there that can lend a hand for a few minutes. I checked all the include files and they are good, and also checked all directories and they are good, I'm currently at a loss on this one guys please help

Share this post


Link to post
Share on other sites
Mat

I'd just increase the array size by one, then try. Usually you're out by one and it's faster to check by running than actually working out what you've done wrong.

Share this post


Link to post
Share on other sites
Haagimus

I'll give that a shot and see if it fixes it

[EDIT]

Alright I have been out of the code for a few months now, read the includes and checked out a few other forums, how do I increase the array size again.....I feel dumb for asking lol

Edited by Haagimus

Share this post


Link to post
Share on other sites
Mat

I'll give that a shot and see if it fixes it

[EDIT]

Alright I have been out of the code for a few months now, read the includes and checked out a few other forums, how do I increase the array size again.....I feel dumb for asking lol

I'd try changing this line:

Global $FilteredFiles[$Files[0]][2]

To

Global $FilteredFiles[$Files[0] + 1][2]

Share this post


Link to post
Share on other sites
Haagimus

testing now

New Files TXT output.au3 (22) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$FilteredFiles[$FilteredFiles[0][0] + 1][1] = $Files[$iFile]
^ ERROR

Same error different line now :ermm:

Okay now I have a new error that is not in my code?

C:\Program Files (x86)\AutoIt3\Include\file.au3 (272) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$s_Temp &= $s_Delim & $a_Array[$x][$y]
$s_Temp &= $s_Delim & ^ ERROR

I don't really want to go messing around with an include file so what should I do

Edited by Haagimus

Share this post


Link to post
Share on other sites
guinness

Strange because that line doesn't even appear in the code you provided above.

Use the following commands to check if the array is in bounds or search _IsInBounds too.

UBound
ReDim
If

Mat has explained the issue, imagine you have a table with 10 rows and you're trying to check the 11th row, which doesn't exist. So you need to work out your logic on accessing the array data.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Haagimus

I have not had a chance to try this to see the result the last few days I have been swamped at work and with school. I will try to test this out next week and get back to you guys

Share this post


Link to post
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
Sign in to follow this  

×