Jump to content

File List Auto Updater


Recommended Posts

Hi, i've created a little program that will run in the background and check a specified folder for file changes (if there's more or less files since last check), and it'll write the updated list of files to a text file.

It worked fine until i wanted to make it able to be customizeable, so that users can choose the folder themselves, without having to edit the script, so i tried that.

But somehow it doesn't work so well.

Here's my source... hope some1 can help me :)

#Include <File.au3>
#Include <Array.au3>
#Include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode",1)

TraySetState()
TraySetToolTip("File List Auto-Update")
TrayTip("File List Auto-Updater Loaded Succesfully!", "This program will check for changes on the folder specified, and will auto-update the list of files in the specified folder into the file: songs.txt * Software Created By SeeR *", 5, 1)

$howto = TrayCreateItem("How to configure")
$filename = TrayCreateItem("File Name")
$selectfolder = TrayCreateItem("Select Folder")
$reset = TrayCreateItem("Reset Config_data")
$aboutitem = TrayCreateItem("About")
$exititem = TrayCreateItem("Exit")
$folderselect = FileSelectFolder("Select folder to check for files", "", 1)
$fileselect = FileSaveDialog("Select name of the file list file", "", "File_List Text File (*.txt)", 2)
$folderinfo = FileReadLine("config.txt", 1)
$fileinfo = FileReadLine("config.txt", 2)
$listfiles = _FileCountLines($fileinfo)
$files = DirGetSize($folderinfo,1)


While 1
    If FileExists( @ScriptDir & "\config.txt") Then
        If $listfiles = $files[1] Then
            Else
                TraySetState(4)
                TrayTip("File List Auto-Update", "File list is now auto-updating...", 2, 1)
                FileDelete($fileinfo)
                Sleep(500)
                $FileList=_FileListToArray($folderinfo)
                $Listed = _ArrayToString($FileList, @CRLF)
                FileWrite($fileinfo, $Listed)
                Sleep(1000)
                TraySetState(8)
                TrayTip("File List Auto-Update", "File list have been updated succesfully!", 2, 1)
        EndIf
    EndIf
        $msg = TrayGetMsg()
        Select
            Case $msg < 1
                ContinueLoop
            Case $msg = $aboutitem
                MsgBox(0,"About", "This software is created by SeeR * © by SeeR * Feel free to use, but don't take the credits for it.")
            Case $msg = $exititem
                ExitLoop
            Case $msg = $selectfolder
                FileWriteLine( @ScriptDir & "\config.txt", $folderselect & @CRLF)       
            Case $msg = $filename
                FileWriteLine( @ScriptDir & "\config.txt", $fileselect & @CRLF)                 
            Case $msg = $howto
                MsgBox(0,"Configuration", "To configure this program correct you need to do the following things: " & @CRLF & "If you already tried to configure, reset the configuration data (click on the programs icon down in right corner)" & @CRLF & "1. Select what folder is going to be checked" & @CRLF & "2. Select the filename for the saved file list (IMPORTANT: you MUST add .txt after the filename when you save" & @CRLF & "3. Don't delete the file 'config.txt'. If you move the .exe file, also move the 'config.txt'" & @CRLF & @CRLF & "Enjoy! © by SeeR")
            Case $msg = $reset
                If FileExists( @ScriptDir & "\config.txt") Then
                    FileDelete( @ScriptDir & "\config.txt")
                    TrayTip("File List Auto-Update", "Config succesfully reset!", 2, 1)
                Else
                    MsgBox(0, "Config file not found!", "The config file needed by File List Auto-Updater could not be found!" & @CRLF & "The file may have been moved, or just not created yet - please follow the instructions and try again")
                EndIf
        EndSelect
WEnd

Exit

One of my other problems is that when the script is loaded/started, the folder and file dialog is opened... and cant really understand that, cause in my code i made it ONLY do that if the file "config.txt" already existed.

Well... hope you can help me out here - i will post the program in here afterwards ofc. :P

Edited by dcer
Link to comment
Share on other sites

Still no one? :)

all nice and fixed for you buddy... tell me if you need to add or remove anything else...

#include <File.au3>
#include <Array.au3>
#include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode", 1)
TraySetState()
TraySetToolTip("File List Auto-Update")
TrayTip("File List Auto-Updater Loaded Succesfully!", "This program will check for changes on the folder specified, and will auto-update the list of files in the specified folder into the file: songs.txt * Software Created By SeeR *", 5, 1)
$howto = TrayCreateItem("How to configure")
$filename = TrayCreateItem("File Name")
$selectfolder = TrayCreateItem("Select Folder")
$reset = TrayCreateItem("Reset Config_data")
$aboutitem = TrayCreateItem("About")
$exititem = TrayCreateItem("Exit")
If FileReadLine("config.txt", 1) = "" Then
    $folderselect = FileSelectFolder("Select folder to check for files", "", 1)
    FileWriteLine("config.txt", $folderselect)
EndIf
If FileReadLine("config.txt", 2) = "" Then
    $fileselect = FileSaveDialog("Select name of the file list file", "", "File_List Text File (*.txt)", 2)
    If StringInStr($fileselect, ".txt") = False Then
        $fileselect = $fileselect & ".txt"
    EndIf
    FileWriteLine("config.txt", $fileselect)
EndIf
$folderinfo = FileReadLine("config.txt", 1)
$fileinfo = FileReadLine("config.txt", 2)
Global $oFiles, $nFiles, $xFiles, $x_Files, $o_Files
CheckFiles()
While 1
    If FileExists(@ScriptDir & "\config.txt") Then
        ReCheck()
        If IsArray($x_Files) And IsArray($o_Files) Then
            For $x = 1 To $x_Files[0]
                If $x_Files[$x] <> $o_Files[$x] Then
                    TraySetState(4)
                    TrayTip("File List Auto-Update", "File list is now auto-updating...", 2, 1)
                    Sleep(100)
                    For $i = 1 To $x_Files[0];checks to see if a file was added to the folder
                        If StringInStr($oFiles, $x_Files[$i]) = False Then
                            $Listed = "Added File:   " & $x_Files[$i]
                        EndIf
                    Next
                    For $i = 1 To $o_Files[0];checks to see if a file was deleted from the folder
                        If StringInStr($xFiles, $o_Files[$i]) = False Then
                            $Listed = "Deleted File:   " & $o_Files[$i]
                        EndIf
                    Next
                    FileWrite($fileinfo, $Listed & @CRLF)
                    Sleep(20)
                    TraySetState(8)
                    TrayTip("File List Auto-Update", "File list have been updated succesfully!", 2, 1)
                    CheckFiles()
                EndIf
            Next
        EndIf
    EndIf
    $msg = TrayGetMsg()
    Select
        Case $msg < 1
            ContinueLoop
        Case $msg = $aboutitem
            MsgBox(0, "About", "This software is created by SeeR * © by SeeR * Feel free to use, but don't take the credits for it.")
        Case $msg = $exititem
            ExitLoop
        Case $msg = $selectfolder
            FileWriteLine(@ScriptDir & "\config.txt", $folderselect & @CRLF)
        Case $msg = $filename
            FileWriteLine(@ScriptDir & "\config.txt", $fileselect & @CRLF)
        Case $msg = $howto
            MsgBox(0, "Configuration", "To configure this program correct you need to do the following things: " & @CRLF & "If you already tried to configure, reset the configuration data (click on the programs icon down in right corner)" & @CRLF & "1. Select what folder is going to be checked" & @CRLF & "2. Select the filename for the saved file list (IMPORTANT: you MUST add .txt after the filename when you save" & @CRLF & "3. Don't delete the file 'config.txt'. If you move the .exe file, also move the 'config.txt'" & @CRLF & @CRLF & "Enjoy! © by SeeR")
        Case $msg = $reset
            If FileExists(@ScriptDir & "\config.txt") Then
                FileDelete(@ScriptDir & "\config.txt")
                TrayTip("File List Auto-Update", "Config succesfully reset!", 2, 1)
            Else
                MsgBox(0, "Config file not found!", "The config file needed by File List Auto-Updater could not be found!" & @CRLF & "The file may have been moved, or just not created yet - please follow the instructions and try again")
            EndIf
    EndSelect
WEnd
Exit
Func CheckFiles()
    $files = ""
    $oFiles = ""
    $o_Files = ""
    $files = _FileListToArray($folderinfo)
    If IsArray($files) Then
        For $x = 1 To $files[0]
            $oFiles = ($oFiles & $folderinfo & "\" & $files[$x] & ";")
        Next
    EndIf
    $oFiles = StringTrimRight($oFiles, 1)
    $o_Files = StringSplit($oFiles, ";")
EndFunc  ;==>CheckFiles
Func ReCheck()
    $nFiles = ""
    $x_Files = ""
    $xFiles = ""
    $nFiles = _FileListToArray($folderinfo)
    If IsArray($nFiles) Then
        For $x = 1 To $nFiles[0]
            $xFiles = ($xFiles & $folderinfo & "\" & $nFiles[$x] & ";")
        Next
    EndIf
    $xFiles = StringTrimRight($xFiles, 1)
    
    $x_Files = StringSplit($xFiles, ";")
EndFunc  ;==>ReCheck
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

all nice and fixed for you buddy... tell me if you need to add or remove anything else...

#include <File.au3>
#include <Array.au3>
#include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode", 1)
TraySetState()
TraySetToolTip("File List Auto-Update")
TrayTip("File List Auto-Updater Loaded Succesfully!", "This program will check for changes on the folder specified, and will auto-update the list of files in the specified folder into the file: songs.txt * Software Created By SeeR *", 5, 1)
$howto = TrayCreateItem("How to configure")
$filename = TrayCreateItem("File Name")
$selectfolder = TrayCreateItem("Select Folder")
$reset = TrayCreateItem("Reset Config_data")
$aboutitem = TrayCreateItem("About")
$exititem = TrayCreateItem("Exit")
If FileReadLine("config.txt", 1) = "" Then
    $folderselect = FileSelectFolder("Select folder to check for files", "", 1)
    FileWriteLine("config.txt", $folderselect)
EndIf
If FileReadLine("config.txt", 2) = "" Then
    $fileselect = FileSaveDialog("Select name of the file list file", "", "File_List Text File (*.txt)", 2)
    If StringInStr($fileselect, ".txt") = False Then
        $fileselect = $fileselect & ".txt"
    EndIf
    FileWriteLine("config.txt", $fileselect)
EndIf
$folderinfo = FileReadLine("config.txt", 1)
$fileinfo = FileReadLine("config.txt", 2)
Global $oFiles, $nFiles, $xFiles, $x_Files, $o_Files
CheckFiles()
While 1
    If FileExists(@ScriptDir & "\config.txt") Then
        ReCheck()
        If IsArray($x_Files) And IsArray($o_Files) Then
            For $x = 1 To $x_Files[0]
                If $x_Files[$x] <> $o_Files[$x] Then
                    TraySetState(4)
                    TrayTip("File List Auto-Update", "File list is now auto-updating...", 2, 1)
                    Sleep(100)
                    For $i = 1 To $x_Files[0];checks to see if a file was added to the folder
                        If StringInStr($oFiles, $x_Files[$i]) = False Then
                            $Listed = "Added File:   " & $x_Files[$i]
                        EndIf
                    Next
                    For $i = 1 To $o_Files[0];checks to see if a file was deleted from the folder
                        If StringInStr($xFiles, $o_Files[$i]) = False Then
                            $Listed = "Deleted File:   " & $o_Files[$i]
                        EndIf
                    Next
                    FileWrite($fileinfo, $Listed & @CRLF)
                    Sleep(20)
                    TraySetState(8)
                    TrayTip("File List Auto-Update", "File list have been updated succesfully!", 2, 1)
                    CheckFiles()
                EndIf
            Next
        EndIf
    EndIf
    $msg = TrayGetMsg()
    Select
        Case $msg < 1
            ContinueLoop
        Case $msg = $aboutitem
            MsgBox(0, "About", "This software is created by SeeR * © by SeeR * Feel free to use, but don't take the credits for it.")
        Case $msg = $exititem
            ExitLoop
        Case $msg = $selectfolder
            FileWriteLine(@ScriptDir & "\config.txt", $folderselect & @CRLF)
        Case $msg = $filename
            FileWriteLine(@ScriptDir & "\config.txt", $fileselect & @CRLF)
        Case $msg = $howto
            MsgBox(0, "Configuration", "To configure this program correct you need to do the following things: " & @CRLF & "If you already tried to configure, reset the configuration data (click on the programs icon down in right corner)" & @CRLF & "1. Select what folder is going to be checked" & @CRLF & "2. Select the filename for the saved file list (IMPORTANT: you MUST add .txt after the filename when you save" & @CRLF & "3. Don't delete the file 'config.txt'. If you move the .exe file, also move the 'config.txt'" & @CRLF & @CRLF & "Enjoy! © by SeeR")
        Case $msg = $reset
            If FileExists(@ScriptDir & "\config.txt") Then
                FileDelete(@ScriptDir & "\config.txt")
                TrayTip("File List Auto-Update", "Config succesfully reset!", 2, 1)
            Else
                MsgBox(0, "Config file not found!", "The config file needed by File List Auto-Updater could not be found!" & @CRLF & "The file may have been moved, or just not created yet - please follow the instructions and try again")
            EndIf
    EndSelect
WEnd
Exit
Func CheckFiles()
    $files = ""
    $oFiles = ""
    $o_Files = ""
    $files = _FileListToArray($folderinfo)
    If IsArray($files) Then
        For $x = 1 To $files[0]
            $oFiles = ($oFiles & $folderinfo & "\" & $files[$x] & ";")
        Next
    EndIf
    $oFiles = StringTrimRight($oFiles, 1)
    $o_Files = StringSplit($oFiles, ";")
EndFunc ;==>CheckFiles
Func ReCheck()
    $nFiles = ""
    $x_Files = ""
    $xFiles = ""
    $nFiles = _FileListToArray($folderinfo)
    If IsArray($nFiles) Then
        For $x = 1 To $nFiles[0]
            $xFiles = ($xFiles & $folderinfo & "\" & $nFiles[$x] & ";")
        Next
    EndIf
    $xFiles = StringTrimRight($xFiles, 1)
    
    $x_Files = StringSplit($xFiles, ";")
EndFunc ;==>ReCheck
Sad to say it... but it doesn't work :)
Link to comment
Share on other sites

delete the config.txt you were using, and just run the program, it works 100% fine on Vista SP 1 32 bit

I did... and btw i'm running on XP SP3, but it just doesn't work. When i run it, it pops up with the file and folder dialog, which i would like it not to do. But anyway, when i choose the folder and file, and then go in to the config file it only wrote the line with the folder name like e.g. C:/testfolder/folder, but not the file line. Second of all, the file that i choose to save (C:/testfolder/folder/filelist.txt) are not saved and the file doesn't exist in the folder, and the line "C:/testfolder/folder/filelist.txt" doesn't exist in the config.txt either.

And when i click on the icon in the taskbar and choose Select File or Select Folder, nothing happens, exept THEN it writes the previous choosed folder and line to the config.txt, but still no list on files or the file filelist.txt in "C:/testfolder/folder/filelist.txt"

:)

Link to comment
Share on other sites

I did... and btw i'm running on XP SP3, but it just doesn't work. When i run it, it pops up with the file and folder dialog, which i would like it not to do. But anyway, when i choose the folder and file, and then go in to the config file it only wrote the line with the folder name like e.g. C:/testfolder/folder, but not the file line. Second of all, the file that i choose to save (C:/testfolder/folder/filelist.txt) are not saved and the file doesn't exist in the folder, and the line "C:/testfolder/folder/filelist.txt" doesn't exist in the config.txt either.

And when i click on the icon in the taskbar and choose Select File or Select Folder, nothing happens, exept THEN it writes the previous choosed folder and line to the config.txt, but still no list on files or the file filelist.txt in "C:/testfolder/folder/filelist.txt"

:)

it pops up Once then write to config.txt...if line 1 or 2 is deleted it will pop up again (depending on what was deleted)

also, can I get someone else to test it please? works fine as I said on Vista SP 1 32 bit

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
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...