Jump to content

Error: Unknown Function Name


aharker
 Share

Go to solution Solved by kylomas,

Recommended Posts

Almost everything else works on this script except the delete function. I've been mulling through it trying to figure out why it won't work, but I haven't made it very far. When I do the button click in the GUI to "delete" it returns the error: unknown function name (line 9440). I'm hoping I can get some help on this.

Func _delete()

    $aItemsForDeletion = _GUICtrlListView_CreateArray($hListView, Default)
    Local $aDeleteList[1]

    For $i = 1 To UBound($aItemsForDeletion)
        If _GUICtrlListView_GetItemChecked($hListView, $i - 1) Then
            $sDeleteItem = $aItemsForDeletion[$i][1] & $aItemsForDeletion[$i][0] & $aItemsForDeletion[$i][3]
            _ArrayAdd($aDeleteList, $sDeleteItem)
        EndIf
    Next

    If UBound($aDeleteList) = 1 Then
        MsgBox(64, "Info", "You have not selected any files for deletion.")
    Else
        $megaBytes = 0
        _ArrayDelete($aDeleteList, 0)
;~      _ArrayDisplay($aDeleteList)
         GUICtrlSetState($btnDelete, $GUI_DISABLE)
         SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        For $i = 0 To UBound($aDeleteList) - 1
            $megaBytes = $megaBytes + FileGetSize($aDeleteList[$i])
            FileRecycle($aDeleteList[$i])
        Next
         SplashOff()
        MsgBox(64, "Info", "You have deleted " & $i & " files which used " & Round($megaBytes/1048576,2) & " MB of space. Please remeber to clean up your recycle bin.")
         GUICtrlSetState($btnDelete, $GUI_ENABLE)

        _search(1)

    EndIf


EndFunc   ;==>_delete
Link to comment
Share on other sites

Where does this function "_GUICtrlListView_CreateArray" come from?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

You need to provide more information:

Which version of AutoIt do you run?

Which UDFs do you include? Can you post the #include statements of your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

My signature.

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

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

You need to provide more information:

Which version of AutoIt do you run?

Which UDFs do you include? Can you post the #include statements of your script?

 

I'm running version 3.2.0

This is the full script.

;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=logo.ico
#AutoIt3Wrapper_Outfile=PC Records Review.exe
#AutoIt3Wrapper_Res_LegalCopyright=Property of CareSource.
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <GuiListView.au3>

Global $iTimeHorizon = 1

#region ### DISCLAIMER

MsgBox(64, "PC Record Review Utility", "" & @CRLF & "This program allows you to delete files older than " & $iTimeHorizon & " years." & _
        @CRLF & "All deleted local files are sent to Recycle Bin. All deleted network files will require an IT ticket to be recoverable." & @CRLF & "Please use this program responsibly.")

#endregion ### DISCLAIMER

#region ### STARTUP Ops

FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### STARTUP Ops

#region ### START Koda GUI section ### Form=

$iLeftMargin = 10
$iItemHeight = 20
$iItemWidth = 90

$Form1 = GUICreate("PC Records Review Utility 1.0", 915, 568, 122, 124, $WS_SIZEBOX)

$btnDirectory = GUICtrlCreateButton("Search Directory", $iLeftMargin, 30, $iItemWidth, $iItemHeight)
$inpPath = GUICtrlCreateInput("", $iLeftMargin + $iItemWidth + $iLeftMargin, 30, 2 * $iItemWidth, $iItemHeight)


$Label2 = GUICtrlCreateLabel("File Types included in search:", $iLeftMargin, 60, 144, 17)

$ckbDoc = GUICtrlCreateCheckbox("doc / docx", $iLeftMargin, 90, $iItemWidth, $iItemHeight)
$ckbXls = GUICtrlCreateCheckbox("xls / xlsx", $iLeftMargin, 120, $iItemWidth, $iItemHeight)
$ckbPpt = GUICtrlCreateCheckbox("ppt / pptx", $iLeftMargin, 150, $iItemWidth, $iItemHeight)
$ckbTxt = GUICtrlCreateCheckbox("txt", $iLeftMargin, 180, $iItemWidth, $iItemHeight)
$ckbPdf = GUICtrlCreateCheckbox("pdf", $iLeftMargin, 210, $iItemWidth, $iItemHeight)
$ckbZip = GUICtrlCreateCheckbox("zip", $iLeftMargin, 240, $iItemWidth, $iItemHeight)
$ckbJpeg = GUICtrlCreateCheckbox("jpeg", 100, 90, $iItemWidth, $iItemHeight)
$ckbPng = GUICtrlCreateCheckbox("png", 100, 120, $iItemWidth, $iItemHeight)
$ckbHtml = GUICtrlCreateCheckbox("html", 100, 150, $iItemWidth, $iItemHeight)
$ckbMhtl = GUICtrlCreateCheckbox("mhtl", 100, 180, $iItemWidth, $iItemHeight)
$ckbAll = GUICtrlCreateCheckbox("Search all types", 100, 210, $iItemWidth, $iItemHeight)

GUICtrlSetState($ckbDoc, $GUI_CHECKED)
GUICtrlSetState($ckbXls, $GUI_CHECKED)
GUICtrlSetState($ckbPpt, $GUI_CHECKED)
GUICtrlSetState($ckbTxt, $GUI_CHECKED)
GUICtrlSetState($ckbPdf, $GUI_CHECKED)
GUICtrlSetState($ckbZip, $GUI_CHECKED)

GUICtrlSetState($ckbDoc, $GUI_DISABLE)
GUICtrlSetState($ckbXls, $GUI_DISABLE)
GUICtrlSetState($ckbPpt, $GUI_DISABLE)
GUICtrlSetState($ckbTxt, $GUI_DISABLE)
GUICtrlSetState($ckbPdf, $GUI_DISABLE)
GUICtrlSetState($ckbZip, $GUI_DISABLE)


$btnSearch = GUICtrlCreateButton("Search", $iLeftMargin, 290, 129, 41)

$lblFoundCount = GUICtrlCreateLabel("", $iLeftMargin, 343, 160, $iItemHeight)
$btnCheckAll = GUICtrlCreateButton("", $iLeftMargin, 360, 129, 41)
$btnDelete = GUICtrlCreateButton("Delete", 160, 360, 129, 41)

GUICtrlSetState($btnSearch, $GUI_DISABLE)
GUICtrlSetState($btnCheckAll, $GUI_DISABLE)
GUICtrlSetState($btnDelete, $GUI_DISABLE)

;~ $Pic1 = GUICtrlCreatePic("C:\Users\koc.m\My Documents\_ORG\ReInvent\Reinvent white.jpg", 0, 330, 360, 105, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

;~ $hListView = GUICtrlCreateListView("Name|Directory|Date Modified|Type|Size in KB", 300, 0, 600, 530, -1, $iExWindowStyle)
$hListView = GUICtrlCreateListView("", 300, 0, 600, 530, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($hListView, "Name", 170)
_GUICtrlListView_AddColumn($hListView, "Directory", 190)
_GUICtrlListView_AddColumn($hListView, "Date Modified", 110)
_GUICtrlListView_AddColumn($hListView, "Type", 50)
_GUICtrlListView_AddColumn($hListView, "Size in KB", 70)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)


$sSplashPath = "wait.jpg"

GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($hListView)

#endregion ### END Koda GUI section ###

;control used do do check/uncheck all
$iCheck = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($hListView)
            Exit
        Case $btnDirectory
            GUICtrlSetState($btnSearch, $GUI_DISABLE)
            ;get new directory
;~          $sInputDir = FileSelectFolder("Select directory", @HomePath) ;
            $sInputDir = FileSelectFolder("Select directory", "", 0, @MyDocumentsDir) ;
            GUICtrlSetData($inpPath, $sInputDir)
            GUICtrlSetState($btnSearch, $GUI_ENABLE)
        Case $btnSearch
            _search()

        Case $hListView
            _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
        Case $ckbAll

            GUICtrlSetState($ckbJpeg, $GUI_CHECKED)
            GUICtrlSetState($ckbPng, $GUI_CHECKED)
            GUICtrlSetState($ckbHtml, $GUI_CHECKED)
            GUICtrlSetState($ckbMhtl, $GUI_CHECKED)
;~
        Case $btnCheckAll
            $iCheck = $iCheck + 1
            $bCheckAll = 0
            If Mod($iCheck, 2) = 0 Then

                $bCheckAll = True
                GUICtrlSetData($btnCheckAll, "Uncheck All")
            Else
                $bCheckAll = False
                GUICtrlSetData($btnCheckAll, "Check All")
            EndIf
            _GUICtrlListView_SetItemChecked($hListView, -1, $bCheckAll)

        Case $btnDelete
            _delete()

    EndSwitch
WEnd

#region ### CLOSE Ops

_GUICtrlListView_UnRegisterSortCallBack($hListView)
FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### CLOSE Ops


#region ### Functions

Func _delete()

    $aItemsForDeletion = _GUICtrlListView_CreateArray($hListView, Default)
    Local $aDeleteList[1]

    For $i = 1 To UBound($aItemsForDeletion)
        If _GUICtrlListView_GetItemChecked($hListView, $i - 1) Then
            $sDeleteItem = $aItemsForDeletion[$i][1] & $aItemsForDeletion[$i][0] & $aItemsForDeletion[$i][3]
            _ArrayAdd($aDeleteList, $sDeleteItem)
        EndIf
    Next

    If UBound($aDeleteList) = 1 Then
        MsgBox(64, "Info", "You have not selected any files for deletion.")
    Else
        $megaBytes = 0
        _ArrayDelete($aDeleteList, 0)
;~      _ArrayDisplay($aDeleteList)
         GUICtrlSetState($btnDelete, $GUI_DISABLE)
         SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        For $i = 0 To UBound($aDeleteList) - 1
            $megaBytes = $megaBytes + FileGetSize($aDeleteList[$i])
            FileRecycle($aDeleteList[$i])
        Next
         SplashOff()
        MsgBox(64, "Info", "You have deleted " & $i & " files which used " & Round($megaBytes/1048576,2) & " MB of space. Please remeber to clean up your recycle bin.")
         GUICtrlSetState($btnDelete, $GUI_ENABLE)

        _search(1)

    EndIf


EndFunc   ;==>_delete

Func _search($mode = 0)
    ;clear previous search results
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
    ;reset check/uncheck
    $iCheck = 0

    $aExtensions = getExtensions()
    $sInputDir = GUICtrlRead($inpPath)
    If $sInputDir <> "" Then
        SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        ScanFolder($sInputDir, $aExtensions) ;returns txt file with all files found
        displayFiles($mode)
        FileDelete(@ScriptDir & "\FileList.txt")
        GUICtrlSetState($btnCheckAll, $GUI_ENABLE)
        GUICtrlSetState($btnDelete, $GUI_ENABLE)
        GUICtrlSetData($btnCheckAll, "Uncheck All")
        SplashOff()
    Else
        MsgBox(64, "Warning", "Search path is not defined. Please select search directory.")
    EndIf
EndFunc   ;==>_search

Func getExtensions()
    Dim $aExtensions[14]
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[0] = ".doc"
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[1] = ".docx"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[2] = ".xls"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[3] = ".xlsx"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[4] = ".ppt"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[5] = ".pptx"
    If GUICtrlRead($ckbTxt) = $GUI_CHECKED Then $aExtensions[6] = ".txt"
    If GUICtrlRead($ckbPdf) = $GUI_CHECKED Then $aExtensions[7] = ".pdf"
    If GUICtrlRead($ckbZip) = $GUI_CHECKED Then $aExtensions[8] = ".zip"
    If GUICtrlRead($ckbJpeg) = $GUI_CHECKED Then $aExtensions[9] = ".jpeg"
    If GUICtrlRead($ckbPng) = $GUI_CHECKED Then $aExtensions[10] = ".png"
    If GUICtrlRead($ckbHtml) = $GUI_CHECKED Then $aExtensions[11] = ".html"
    If GUICtrlRead($ckbMhtl) = $GUI_CHECKED Then $aExtensions[12] = ".mhtl"
    If GUICtrlRead($ckbAll) = $GUI_CHECKED Then $aExtensions[13] = ".*"
    Return $aExtensions
EndFunc   ;==>getExtensions

Func displayFiles($mode = 0)

    ;step 1 read the FileList.txt and put it into an array
    Local $aFileList
    _FileReadToArray(@ScriptDir & "\FileList.txt", $aFileList)
    If @error Then
        SplashOff()
        If $mode = 0 Then MsgBox(64, "info", "No files older than " & $iTimeHorizon & " years were found in the search directory")
    Else

        Dim $aFileList2[UBound($aFileList)][5]
        Local $szDrive, $szDir, $szFName, $szExt

        For $i = 1 To UBound($aFileList) - 1
            $sFileAttributes = _PathSplit($aFileList[$i], $szDrive, $szDir, $szFName, $szExt)
            $aDateModified = FileGetTime($aFileList[$i], 0, 0)
            $sSize = Round(FileGetSize($aFileList[$i]) / 1024, 2)
            $aFileList2[$i][0] = $sFileAttributes[3] ;name
            $aFileList2[$i][1] = $sFileAttributes[1] & $sFileAttributes[2] ;directory
            $aFileList2[$i][2] = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $aFileList2[$i][3] = $sFileAttributes[4] ;extension
            $aFileList2[$i][4] = $sSize ;filesize in kb

        Next

        _ArraySort($aFileList2, 0, 0, 0, 2)

        GUICtrlSetData($lblFoundCount, $aFileList[0] & " files older than " & $iTimeHorizon & " years found.")
        _ArrayDelete($aFileList2, 0)

;~  _GUICtrlListView_AddArray($hListView, $aFileList2)



        For $i = 0 To UBound($aFileList2) - 1
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFileList2 = ' & $aFileList2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            _GUICtrlListView_AddItem($hListView, $aFileList2[$i][0], -1, _GUICtrlListView_GetItemCount($hListView) + 1000)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][1], 1, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][2], 2, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][3], 3, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][4], 4, -1)
            _GUICtrlListView_SetItemChecked($hListView, $i, True)
        Next

    EndIf


EndFunc   ;==>displayFiles

Func ScanFolder($SourceFolder, $aExtensions)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath


    $Search = FileFindFirstFile($SourceFolder & "\*.*")

    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop

        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)

        If StringInStr($FileAttributes, "D") Then
            ScanFolder($FullFilePath, $aExtensions)
        Else
            $sExt = _FileGetExt($FullFilePath)
            $aDateModified = FileGetTime($FullFilePath, 0, 0)
            $sDateModified = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $iYears = _DateDiff("Y", $sDateModified, _NowCalc())
            If ((_ArraySearch($aExtensions, $sExt) <> -1 Or $aExtensions[13] <> "") And $iYears > $iTimeHorizon) Then LogFile($FullFilePath)
        EndIf

    WEnd

    FileClose($Search)

EndFunc   ;==>ScanFolder

Func LogFile($FileName)
    $fLogFile = FileOpen(@ScriptDir & "\FileList.txt", 1)
;~  FileWriteLine(@ScriptDir & "\FileList.txt",$FileName)
    FileWriteLine($fLogFile, $FileName)
    FileClose($fLogFile)

EndFunc   ;==>LogFile

Func _FileGetExt($sPath)
    Local $NULL, $sExt
    _PathSplit($sPath, $NULL, $NULL, $NULL, $sExt)
    Return $sExt
EndFunc   ;==>_FileGetExt

#endregion ### Functions
Link to comment
Share on other sites

AutoIt version 3.2.0 was released in August 2006.

Do you really expect us to support such an old version?

Why not upgrade to the latest 3.3.10.x version?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm pretty sure the OP is actually referring to the version of SciTE and not the version of AutoIt3.

Aharker, we need to know which version of Autoit you're using, and not the SciTE version if my guess is right.

Also, please post the entire output from SciTE when you attempt to run your code so that we know WHICH function it can't find.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm pretty sure the OP is actually referring to the version of SciTE and not the version of AutoIt3.

Aharker, we need to know which version of Autoit you're using, and not the SciTE version if my guess is right.

Also, please post the entire output from SciTE when you attempt to run your code so that we know WHICH function it can't find.

 

I'm sorry, you're right. I grabbed the version off of SciTE. I had just upgraded to the version released in December (v3.3.8.1).

Here is the entire script again:

;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=logo.ico
#AutoIt3Wrapper_Outfile=PC Records Review.exe
#AutoIt3Wrapper_Res_LegalCopyright=Property of CareSource.
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <GuiListView.au3>

Global $iTimeHorizon = 1

#region ### DISCLAIMER

MsgBox(64, "PC Record Review Utility", "" & @CRLF & "This program allows you to delete files older than " & $iTimeHorizon & " years." & _
        @CRLF & "All deleted local files are sent to Recycle Bin. All deleted network files will require an IT ticket to be recoverable." & @CRLF & "Please use this program responsibly.")

#endregion ### DISCLAIMER

#region ### STARTUP Ops

FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### STARTUP Ops

#region ### START Koda GUI section ### Form=

$iLeftMargin = 10
$iItemHeight = 20
$iItemWidth = 90

$Form1 = GUICreate("PC Records Review Utility 1.0", 915, 568, 122, 124, $WS_SIZEBOX)

$btnDirectory = GUICtrlCreateButton("Search Directory", $iLeftMargin, 30, $iItemWidth, $iItemHeight)
$inpPath = GUICtrlCreateInput("", $iLeftMargin + $iItemWidth + $iLeftMargin, 30, 2 * $iItemWidth, $iItemHeight)


$Label2 = GUICtrlCreateLabel("File Types included in search:", $iLeftMargin, 60, 144, 17)

$ckbDoc = GUICtrlCreateCheckbox("doc / docx", $iLeftMargin, 90, $iItemWidth, $iItemHeight)
$ckbXls = GUICtrlCreateCheckbox("xls / xlsx", $iLeftMargin, 120, $iItemWidth, $iItemHeight)
$ckbPpt = GUICtrlCreateCheckbox("ppt / pptx", $iLeftMargin, 150, $iItemWidth, $iItemHeight)
$ckbTxt = GUICtrlCreateCheckbox("txt", $iLeftMargin, 180, $iItemWidth, $iItemHeight)
$ckbPdf = GUICtrlCreateCheckbox("pdf", $iLeftMargin, 210, $iItemWidth, $iItemHeight)
$ckbZip = GUICtrlCreateCheckbox("zip", $iLeftMargin, 240, $iItemWidth, $iItemHeight)
$ckbJpeg = GUICtrlCreateCheckbox("jpeg", 100, 90, $iItemWidth, $iItemHeight)
$ckbPng = GUICtrlCreateCheckbox("png", 100, 120, $iItemWidth, $iItemHeight)
$ckbHtml = GUICtrlCreateCheckbox("html", 100, 150, $iItemWidth, $iItemHeight)
$ckbMhtl = GUICtrlCreateCheckbox("mhtl", 100, 180, $iItemWidth, $iItemHeight)
$ckbAll = GUICtrlCreateCheckbox("Search all types", 100, 210, $iItemWidth, $iItemHeight)

GUICtrlSetState($ckbDoc, $GUI_CHECKED)
GUICtrlSetState($ckbXls, $GUI_CHECKED)
GUICtrlSetState($ckbPpt, $GUI_CHECKED)
GUICtrlSetState($ckbTxt, $GUI_CHECKED)
GUICtrlSetState($ckbPdf, $GUI_CHECKED)
GUICtrlSetState($ckbZip, $GUI_CHECKED)

GUICtrlSetState($ckbDoc, $GUI_DISABLE)
GUICtrlSetState($ckbXls, $GUI_DISABLE)
GUICtrlSetState($ckbPpt, $GUI_DISABLE)
GUICtrlSetState($ckbTxt, $GUI_DISABLE)
GUICtrlSetState($ckbPdf, $GUI_DISABLE)
GUICtrlSetState($ckbZip, $GUI_DISABLE)


$btnSearch = GUICtrlCreateButton("Search", $iLeftMargin, 290, 129, 41)

$lblFoundCount = GUICtrlCreateLabel("", $iLeftMargin, 343, 160, $iItemHeight)
$btnCheckAll = GUICtrlCreateButton("", $iLeftMargin, 360, 129, 41)
$btnDelete = GUICtrlCreateButton("Delete", 160, 360, 129, 41)

GUICtrlSetState($btnSearch, $GUI_DISABLE)
GUICtrlSetState($btnCheckAll, $GUI_DISABLE)
GUICtrlSetState($btnDelete, $GUI_DISABLE)

;~ $Pic1 = GUICtrlCreatePic("C:\Users\koc.m\My Documents\_ORG\ReInvent\Reinvent white.jpg", 0, 330, 360, 105, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

;~ $hListView = GUICtrlCreateListView("Name|Directory|Date Modified|Type|Size in KB", 300, 0, 600, 530, -1, $iExWindowStyle)
$hListView = GUICtrlCreateListView("", 300, 0, 600, 530, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($hListView, "Name", 170)
_GUICtrlListView_AddColumn($hListView, "Directory", 190)
_GUICtrlListView_AddColumn($hListView, "Date Modified", 110)
_GUICtrlListView_AddColumn($hListView, "Type", 50)
_GUICtrlListView_AddColumn($hListView, "Size in KB", 70)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)


$sSplashPath = "wait.jpg"

GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($hListView)

#endregion ### END Koda GUI section ###

;control used do do check/uncheck all
$iCheck = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($hListView)
            Exit
        Case $btnDirectory
            GUICtrlSetState($btnSearch, $GUI_DISABLE)
            ;get new directory
;~          $sInputDir = FileSelectFolder("Select directory", @HomePath) ;
            $sInputDir = FileSelectFolder("Select directory", "", 0, @MyDocumentsDir) ;
            GUICtrlSetData($inpPath, $sInputDir)
            GUICtrlSetState($btnSearch, $GUI_ENABLE)
        Case $btnSearch
            _search()

        Case $hListView
            _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
        Case $ckbAll

            GUICtrlSetState($ckbJpeg, $GUI_CHECKED)
            GUICtrlSetState($ckbPng, $GUI_CHECKED)
            GUICtrlSetState($ckbHtml, $GUI_CHECKED)
            GUICtrlSetState($ckbMhtl, $GUI_CHECKED)
;~
        Case $btnCheckAll
            $iCheck = $iCheck + 1
            $bCheckAll = 0
            If Mod($iCheck, 2) = 0 Then

                $bCheckAll = True
                GUICtrlSetData($btnCheckAll, "Uncheck All")
            Else
                $bCheckAll = False
                GUICtrlSetData($btnCheckAll, "Check All")
            EndIf
            _GUICtrlListView_SetItemChecked($hListView, -1, $bCheckAll)

        Case $btnDelete
            _delete()

    EndSwitch
WEnd

#region ### CLOSE Ops

_GUICtrlListView_UnRegisterSortCallBack($hListView)
FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### CLOSE Ops


#region ### Functions

Func _delete()

    $aItemsForDeletion = _GUICtrlListView_CreateArray($hListView, Default)
    Local $aDeleteList[1]

    For $i = 1 To UBound($aItemsForDeletion)
        If _GUICtrlListView_GetItemChecked($hListView, $i - 1) Then
            $sDeleteItem = $aItemsForDeletion[$i][1] & $aItemsForDeletion[$i][0] & $aItemsForDeletion[$i][3]
            _ArrayAdd($aDeleteList, $sDeleteItem)
        EndIf
    Next

    If UBound($aDeleteList) = 1 Then
        MsgBox(64, "Info", "You have not selected any files for deletion.")
    Else
        $megaBytes = 0
        _ArrayDelete($aDeleteList, 0)
;~      _ArrayDisplay($aDeleteList)
         GUICtrlSetState($btnDelete, $GUI_DISABLE)
         SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        For $i = 0 To UBound($aDeleteList) - 1
            $megaBytes = $megaBytes + FileGetSize($aDeleteList[$i])
            FileRecycle($aDeleteList[$i])
        Next
         SplashOff()
        MsgBox(64, "Info", "You have deleted " & $i & " files which used " & Round($megaBytes/1048576,2) & " MB of space. Please remeber to clean up your recycle bin.")
         GUICtrlSetState($btnDelete, $GUI_ENABLE)

        _search(1)

    EndIf


EndFunc   ;==>_delete

Func _search($mode = 0)
    ;clear previous search results
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
    ;reset check/uncheck
    $iCheck = 0

    $aExtensions = getExtensions()
    $sInputDir = GUICtrlRead($inpPath)
    If $sInputDir <> "" Then
        SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        ScanFolder($sInputDir, $aExtensions) ;returns txt file with all files found
        displayFiles($mode)
        FileDelete(@ScriptDir & "\FileList.txt")
        GUICtrlSetState($btnCheckAll, $GUI_ENABLE)
        GUICtrlSetState($btnDelete, $GUI_ENABLE)
        GUICtrlSetData($btnCheckAll, "Uncheck All")
        SplashOff()
    Else
        MsgBox(64, "Warning", "Search path is not defined. Please select search directory.")
    EndIf
EndFunc   ;==>_search

Func getExtensions()
    Dim $aExtensions[14]
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[0] = ".doc"
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[1] = ".docx"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[2] = ".xls"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[3] = ".xlsx"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[4] = ".ppt"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[5] = ".pptx"
    If GUICtrlRead($ckbTxt) = $GUI_CHECKED Then $aExtensions[6] = ".txt"
    If GUICtrlRead($ckbPdf) = $GUI_CHECKED Then $aExtensions[7] = ".pdf"
    If GUICtrlRead($ckbZip) = $GUI_CHECKED Then $aExtensions[8] = ".zip"
    If GUICtrlRead($ckbJpeg) = $GUI_CHECKED Then $aExtensions[9] = ".jpeg"
    If GUICtrlRead($ckbPng) = $GUI_CHECKED Then $aExtensions[10] = ".png"
    If GUICtrlRead($ckbHtml) = $GUI_CHECKED Then $aExtensions[11] = ".html"
    If GUICtrlRead($ckbMhtl) = $GUI_CHECKED Then $aExtensions[12] = ".mhtl"
    If GUICtrlRead($ckbAll) = $GUI_CHECKED Then $aExtensions[13] = ".*"
    Return $aExtensions
EndFunc   ;==>getExtensions

Func displayFiles($mode = 0)

    ;step 1 read the FileList.txt and put it into an array
    Local $aFileList
    _FileReadToArray(@ScriptDir & "\FileList.txt", $aFileList)
    If @error Then
        SplashOff()
        If $mode = 0 Then MsgBox(64, "info", "No files older than " & $iTimeHorizon & " years were found in the search directory")
    Else

        Dim $aFileList2[UBound($aFileList)][5]
        Local $szDrive, $szDir, $szFName, $szExt

        For $i = 1 To UBound($aFileList) - 1
            $sFileAttributes = _PathSplit($aFileList[$i], $szDrive, $szDir, $szFName, $szExt)
            $aDateModified = FileGetTime($aFileList[$i], 0, 0)
            $sSize = Round(FileGetSize($aFileList[$i]) / 1024, 2)
            $aFileList2[$i][0] = $sFileAttributes[3] ;name
            $aFileList2[$i][1] = $sFileAttributes[1] & $sFileAttributes[2] ;directory
            $aFileList2[$i][2] = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $aFileList2[$i][3] = $sFileAttributes[4] ;extension
            $aFileList2[$i][4] = $sSize ;filesize in kb

        Next

        _ArraySort($aFileList2, 0, 0, 0, 2)

        GUICtrlSetData($lblFoundCount, $aFileList[0] & " files older than " & $iTimeHorizon & " years found.")
        _ArrayDelete($aFileList2, 0)

;~  _GUICtrlListView_AddArray($hListView, $aFileList2)



        For $i = 0 To UBound($aFileList2) - 1
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFileList2 = ' & $aFileList2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            _GUICtrlListView_AddItem($hListView, $aFileList2[$i][0], -1, _GUICtrlListView_GetItemCount($hListView) + 1000)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][1], 1, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][2], 2, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][3], 3, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][4], 4, -1)
            _GUICtrlListView_SetItemChecked($hListView, $i, True)
        Next

    EndIf


EndFunc   ;==>displayFiles

Func ScanFolder($SourceFolder, $aExtensions)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath


    $Search = FileFindFirstFile($SourceFolder & "\*.*")

    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop

        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)

        If StringInStr($FileAttributes, "D") Then
            ScanFolder($FullFilePath, $aExtensions)
        Else
            $sExt = _FileGetExt($FullFilePath)
            $aDateModified = FileGetTime($FullFilePath, 0, 0)
            $sDateModified = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $iYears = _DateDiff("Y", $sDateModified, _NowCalc())
            If ((_ArraySearch($aExtensions, $sExt) <> -1 Or $aExtensions[13] <> "") And $iYears > $iTimeHorizon) Then LogFile($FullFilePath)
        EndIf

    WEnd

    FileClose($Search)

EndFunc   ;==>ScanFolder

Func LogFile($FileName)
    $fLogFile = FileOpen(@ScriptDir & "\FileList.txt", 1)
;~  FileWriteLine(@ScriptDir & "\FileList.txt",$FileName)
    FileWriteLine($fLogFile, $FileName)
    FileClose($fLogFile)

EndFunc   ;==>LogFile

Func _FileGetExt($sPath)
    Local $NULL, $sExt
    _PathSplit($sPath, $NULL, $NULL, $NULL, $sExt)
    Return $sExt
EndFunc   ;==>_FileGetExt

#endregion ### Functions
Link to comment
Share on other sites

  • Solution

aharker,

Works fiine for me after I added the missing function from guinness's sig...

;#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=logo.ico
#AutoIt3Wrapper_Outfile=PC Records Review.exe
#AutoIt3Wrapper_Res_LegalCopyright=Property of CareSource.
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <GuiListView.au3>

Global $iTimeHorizon = 1

#region ### DISCLAIMER

MsgBox(64, "PC Record Review Utility", "" & @CRLF & "This program allows you to delete files older than " & $iTimeHorizon & " years." & _
        @CRLF & "All deleted local files are sent to Recycle Bin. All deleted network files will require an IT ticket to be recoverable." & @CRLF & "Please use this program responsibly.")

#endregion ### DISCLAIMER

#region ### STARTUP Ops

FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### STARTUP Ops

#region ### START Koda GUI section ### Form=

$iLeftMargin = 10
$iItemHeight = 20
$iItemWidth = 90

$Form1 = GUICreate("PC Records Review Utility 1.0", 915, 568, 122, 124, $WS_SIZEBOX)

$btnDirectory = GUICtrlCreateButton("Search Directory", $iLeftMargin, 30, $iItemWidth, $iItemHeight)
$inpPath = GUICtrlCreateInput("", $iLeftMargin + $iItemWidth + $iLeftMargin, 30, 2 * $iItemWidth, $iItemHeight)


$Label2 = GUICtrlCreateLabel("File Types included in search:", $iLeftMargin, 60, 144, 17)

$ckbDoc = GUICtrlCreateCheckbox("doc / docx", $iLeftMargin, 90, $iItemWidth, $iItemHeight)
$ckbXls = GUICtrlCreateCheckbox("xls / xlsx", $iLeftMargin, 120, $iItemWidth, $iItemHeight)
$ckbPpt = GUICtrlCreateCheckbox("ppt / pptx", $iLeftMargin, 150, $iItemWidth, $iItemHeight)
$ckbTxt = GUICtrlCreateCheckbox("txt", $iLeftMargin, 180, $iItemWidth, $iItemHeight)
$ckbPdf = GUICtrlCreateCheckbox("pdf", $iLeftMargin, 210, $iItemWidth, $iItemHeight)
$ckbZip = GUICtrlCreateCheckbox("zip", $iLeftMargin, 240, $iItemWidth, $iItemHeight)
$ckbJpeg = GUICtrlCreateCheckbox("jpeg", 100, 90, $iItemWidth, $iItemHeight)
$ckbPng = GUICtrlCreateCheckbox("png", 100, 120, $iItemWidth, $iItemHeight)
$ckbHtml = GUICtrlCreateCheckbox("html", 100, 150, $iItemWidth, $iItemHeight)
$ckbMhtl = GUICtrlCreateCheckbox("mhtl", 100, 180, $iItemWidth, $iItemHeight)
$ckbAll = GUICtrlCreateCheckbox("Search all types", 100, 210, $iItemWidth, $iItemHeight)

GUICtrlSetState($ckbDoc, $GUI_CHECKED)
GUICtrlSetState($ckbXls, $GUI_CHECKED)
GUICtrlSetState($ckbPpt, $GUI_CHECKED)
GUICtrlSetState($ckbTxt, $GUI_CHECKED)
GUICtrlSetState($ckbPdf, $GUI_CHECKED)
GUICtrlSetState($ckbZip, $GUI_CHECKED)

GUICtrlSetState($ckbDoc, $GUI_DISABLE)
GUICtrlSetState($ckbXls, $GUI_DISABLE)
GUICtrlSetState($ckbPpt, $GUI_DISABLE)
GUICtrlSetState($ckbTxt, $GUI_DISABLE)
GUICtrlSetState($ckbPdf, $GUI_DISABLE)
GUICtrlSetState($ckbZip, $GUI_DISABLE)


$btnSearch = GUICtrlCreateButton("Search", $iLeftMargin, 290, 129, 41)

$lblFoundCount = GUICtrlCreateLabel("", $iLeftMargin, 343, 160, $iItemHeight)
$btnCheckAll = GUICtrlCreateButton("", $iLeftMargin, 360, 129, 41)
$btnDelete = GUICtrlCreateButton("Delete", 160, 360, 129, 41)

GUICtrlSetState($btnSearch, $GUI_DISABLE)
GUICtrlSetState($btnCheckAll, $GUI_DISABLE)
GUICtrlSetState($btnDelete, $GUI_DISABLE)

;~ $Pic1 = GUICtrlCreatePic("C:\Users\koc.m\My Documents\_ORG\ReInvent\Reinvent white.jpg", 0, 330, 360, 105, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))

Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

;~ $hListView = GUICtrlCreateListView("Name|Directory|Date Modified|Type|Size in KB", 300, 0, 600, 530, -1, $iExWindowStyle)
$hListView = GUICtrlCreateListView("", 300, 0, 600, 530, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($hListView, "Name", 170)
_GUICtrlListView_AddColumn($hListView, "Directory", 190)
_GUICtrlListView_AddColumn($hListView, "Date Modified", 110)
_GUICtrlListView_AddColumn($hListView, "Type", 50)
_GUICtrlListView_AddColumn($hListView, "Size in KB", 70)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)


$sSplashPath = "wait.jpg"

GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($hListView)

#endregion ### END Koda GUI section ###

;control used do do check/uncheck all
$iCheck = 0
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($hListView)
            Exit
        Case $btnDirectory
            GUICtrlSetState($btnSearch, $GUI_DISABLE)
            ;get new directory
;~          $sInputDir = FileSelectFolder("Select directory", @HomePath) ;
            $sInputDir = FileSelectFolder("Select directory", "", 0, @MyDocumentsDir) ;
            GUICtrlSetData($inpPath, $sInputDir)
            GUICtrlSetState($btnSearch, $GUI_ENABLE)
        Case $btnSearch
            _search()

        Case $hListView
            _GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
        Case $ckbAll

            GUICtrlSetState($ckbJpeg, $GUI_CHECKED)
            GUICtrlSetState($ckbPng, $GUI_CHECKED)
            GUICtrlSetState($ckbHtml, $GUI_CHECKED)
            GUICtrlSetState($ckbMhtl, $GUI_CHECKED)
;~
        Case $btnCheckAll
            $iCheck = $iCheck + 1
            $bCheckAll = 0
            If Mod($iCheck, 2) = 0 Then

                $bCheckAll = True
                GUICtrlSetData($btnCheckAll, "Uncheck All")
            Else
                $bCheckAll = False
                GUICtrlSetData($btnCheckAll, "Check All")
            EndIf
            _GUICtrlListView_SetItemChecked($hListView, -1, $bCheckAll)

        Case $btnDelete
            _delete()

    EndSwitch
WEnd

#region ### CLOSE Ops

_GUICtrlListView_UnRegisterSortCallBack($hListView)
FileDelete(@ScriptDir & "\FileList.txt")

#endregion ### CLOSE Ops


#region ### Functions

Func _delete()

    $aItemsForDeletion = _GUICtrlListView_CreateArray($hListView, Default)
    Local $aDeleteList[1]

    For $i = 1 To UBound($aItemsForDeletion)
        If _GUICtrlListView_GetItemChecked($hListView, $i - 1) Then
            $sDeleteItem = $aItemsForDeletion[$i][1] & $aItemsForDeletion[$i][0] & $aItemsForDeletion[$i][3]
            _ArrayAdd($aDeleteList, $sDeleteItem)
        EndIf
    Next

    If UBound($aDeleteList) = 1 Then
        MsgBox(64, "Info", "You have not selected any files for deletion.")
    Else
        $megaBytes = 0
        _ArrayDelete($aDeleteList, 0)
;~      _ArrayDisplay($aDeleteList)
         GUICtrlSetState($btnDelete, $GUI_DISABLE)
         SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        For $i = 0 To UBound($aDeleteList) - 1
            $megaBytes = $megaBytes + FileGetSize($aDeleteList[$i])
            FileRecycle($aDeleteList[$i])
        Next
         SplashOff()
        MsgBox(64, "Info", "You have deleted " & $i & " files which used " & Round($megaBytes/1048576,2) & " MB of space. Please remeber to clean up your recycle bin.")
         GUICtrlSetState($btnDelete, $GUI_ENABLE)

        _search(1)

    EndIf


EndFunc   ;==>_delete

Func _search($mode = 0)
    ;clear previous search results
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
    ;reset check/uncheck
    $iCheck = 0

    $aExtensions = getExtensions()
    $sInputDir = GUICtrlRead($inpPath)
    If $sInputDir <> "" Then
        SplashImageOn("", $sSplashPath, 467, 85, Default, Default, 1)
        ScanFolder($sInputDir, $aExtensions) ;returns txt file with all files found
        displayFiles($mode)
        FileDelete(@ScriptDir & "\FileList.txt")
        GUICtrlSetState($btnCheckAll, $GUI_ENABLE)
        GUICtrlSetState($btnDelete, $GUI_ENABLE)
        GUICtrlSetData($btnCheckAll, "Uncheck All")
        SplashOff()
    Else
        MsgBox(64, "Warning", "Search path is not defined. Please select search directory.")
    EndIf
EndFunc   ;==>_search

Func getExtensions()
    Dim $aExtensions[14]
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[0] = ".doc"
    If GUICtrlRead($ckbDoc) = $GUI_CHECKED Then $aExtensions[1] = ".docx"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[2] = ".xls"
    If GUICtrlRead($ckbXls) = $GUI_CHECKED Then $aExtensions[3] = ".xlsx"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[4] = ".ppt"
    If GUICtrlRead($ckbPpt) = $GUI_CHECKED Then $aExtensions[5] = ".pptx"
    If GUICtrlRead($ckbTxt) = $GUI_CHECKED Then $aExtensions[6] = ".txt"
    If GUICtrlRead($ckbPdf) = $GUI_CHECKED Then $aExtensions[7] = ".pdf"
    If GUICtrlRead($ckbZip) = $GUI_CHECKED Then $aExtensions[8] = ".zip"
    If GUICtrlRead($ckbJpeg) = $GUI_CHECKED Then $aExtensions[9] = ".jpeg"
    If GUICtrlRead($ckbPng) = $GUI_CHECKED Then $aExtensions[10] = ".png"
    If GUICtrlRead($ckbHtml) = $GUI_CHECKED Then $aExtensions[11] = ".html"
    If GUICtrlRead($ckbMhtl) = $GUI_CHECKED Then $aExtensions[12] = ".mhtl"
    If GUICtrlRead($ckbAll) = $GUI_CHECKED Then $aExtensions[13] = ".*"
    Return $aExtensions
EndFunc   ;==>getExtensions

Func displayFiles($mode = 0)

    ;step 1 read the FileList.txt and put it into an array
    Local $aFileList
    _FileReadToArray(@ScriptDir & "\FileList.txt", $aFileList)
    If @error Then
        SplashOff()
        If $mode = 0 Then MsgBox(64, "info", "No files older than " & $iTimeHorizon & " years were found in the search directory")
    Else

        Dim $aFileList2[UBound($aFileList)][5]
        Local $szDrive, $szDir, $szFName, $szExt

        For $i = 1 To UBound($aFileList) - 1
            $sFileAttributes = _PathSplit($aFileList[$i], $szDrive, $szDir, $szFName, $szExt)
            $aDateModified = FileGetTime($aFileList[$i], 0, 0)
            $sSize = Round(FileGetSize($aFileList[$i]) / 1024, 2)
            $aFileList2[$i][0] = $sFileAttributes[3] ;name
            $aFileList2[$i][1] = $sFileAttributes[1] & $sFileAttributes[2] ;directory
            $aFileList2[$i][2] = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $aFileList2[$i][3] = $sFileAttributes[4] ;extension
            $aFileList2[$i][4] = $sSize ;filesize in kb

        Next

        _ArraySort($aFileList2, 0, 0, 0, 2)

        GUICtrlSetData($lblFoundCount, $aFileList[0] & " files older than " & $iTimeHorizon & " years found.")
        _ArrayDelete($aFileList2, 0)

;~  _GUICtrlListView_AddArray($hListView, $aFileList2)



        For $i = 0 To UBound($aFileList2) - 1
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFileList2 = ' & $aFileList2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            _GUICtrlListView_AddItem($hListView, $aFileList2[$i][0], -1, _GUICtrlListView_GetItemCount($hListView) + 1000)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][1], 1, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][2], 2, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][3], 3, -1)
            _GUICtrlListView_AddSubItem($hListView, $i, $aFileList2[$i][4], 4, -1)
            _GUICtrlListView_SetItemChecked($hListView, $i, True)
        Next

    EndIf


EndFunc   ;==>displayFiles

Func ScanFolder($SourceFolder, $aExtensions)
    Local $Search
    Local $File
    Local $FileAttributes
    Local $FullFilePath


    $Search = FileFindFirstFile($SourceFolder & "\*.*")

    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop

        $FullFilePath = $SourceFolder & "\" & $File
        $FileAttributes = FileGetAttrib($FullFilePath)

        If StringInStr($FileAttributes, "D") Then
            ScanFolder($FullFilePath, $aExtensions)
        Else
            $sExt = _FileGetExt($FullFilePath)
            $aDateModified = FileGetTime($FullFilePath, 0, 0)
            $sDateModified = $aDateModified[0] & "/" & $aDateModified[1] & "/" & $aDateModified[2] & " " & $aDateModified[3] & ":" & $aDateModified[4] & ":" & $aDateModified[5]
            $iYears = _DateDiff("Y", $sDateModified, _NowCalc())
            If ((_ArraySearch($aExtensions, $sExt) <> -1 Or $aExtensions[13] <> "") And $iYears > $iTimeHorizon) Then LogFile($FullFilePath)
        EndIf

    WEnd

    FileClose($Search)

EndFunc   ;==>ScanFolder

Func LogFile($FileName)
    $fLogFile = FileOpen(@ScriptDir & "\FileList.txt", 1)
;~  FileWriteLine(@ScriptDir & "\FileList.txt",$FileName)
    FileWriteLine($fLogFile, $FileName)
    FileClose($fLogFile)

EndFunc   ;==>LogFile

Func _FileGetExt($sPath)
    Local $NULL, $sExt
    _PathSplit($sPath, $NULL, $NULL, $NULL, $sExt)
    Return $sExt
EndFunc   ;==>_FileGetExt

#endregion ### Functions

; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlListView_CreateArray
; Description ...: Creates a 2-dimensional array from a listview.
; Syntax ........: _GUICtrlListView_CreateArray($hListView[, $sDelimeter = '|'])
; Parameters ....: $hListView           - Control ID/Handle to the control
;                  $sDelimeter          - [optional] One or more characters to use as delimiters (case sensitive). Default is '|'.
; Return values .: Success - The array returned is two-dimensional and is made up of the following:
;                                $aArray[0][0] = Number of rows
;                                $aArray[0][1] = Number of columns
;                                $aArray[0][2] = Delimited string of the column name(s) e.g. Column 1|Column 2|Column 3|Column nth

;                                $aArray[1][0] = 1st row, 1st column
;                                $aArray[1][1] = 1st row, 2nd column
;                                $aArray[1][2] = 1st row, 3rd column
;                                $aArray[n][0] = nth row, 1st column
;                                $aArray[n][1] = nth row, 2nd column
;                                $aArray[n][2] = nth row, 3rd column
; Author ........: guinness
; Remarks .......: GUICtrlListView.au3 should be included.
; Example .......: Yes
; ===============================================================================================================================
Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|')
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView)
    If $iColumnCount < 3 Then
        $iDim = 3 - $iColumnCount
    EndIf
    If $sDelimeter = Default Then
        $sDelimeter = '|'
    EndIf

    Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
    For $i = 0 To $iColumnCount - 1
        $aColumns = _GUICtrlListView_GetColumn($hListView, $i)
        $aReturn[0][2] &= $aColumns[5] & $sDelimeter
    Next
    $aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))

    For $i = 0 To $iItemCount - 1
        For $j = 0 To $iColumnCount - 1
            $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
        Next
    Next
    Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc   ;==>_GUICtrlListView_CreateArray

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Yes, you're missing the _GUICtrlListView_CreateArray() function from your script. This is not a standard function included with AutoIt.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...