Jump to content

InIRead All Selection


Demon777
 Share

Recommended Posts

Hello everyone. I got little prob here.

I have an ini file. This ini file has following keys...

:-------------------------

[Files]

FilePath1 = C:\Path\File

FileUrl1 = http://site/file

FilePath2 = C:\Path\File

FileUrl2 = http://site/file

FilePath3 = C:\Path\File

FileUrl3 = http://site/file

:-------------------------

So. My script should check if file exist under FilePath, if not then download this file from FileUrl.

So this is what i have atm :

Func _Check()
    $Filelist = @ScriptDir & "\Filelist.bin"
    $List = IniReadSection($Filelist, "Files")
    
    For $i = 1 To $List[0][0]
        If FileExists($List[$i][1]) Then
            Sleep(100)
        Else
            ;Get file from inet under fileurl.
                        ;I have no idea how to get this url for right file.
                Endif
        Next
EndFunc

After it has checked all files it should exit. Thx. So is there any way to do it ?

Link to comment
Share on other sites

This is a new try...

Func _Check()
    $Filelist = @ScriptDir & "\Filelist.bin"
    $List = IniReadSection($Filelist, "Files")
    $Number = 1
    For $i = 1 To $List[0]
        Local $url = IniRead($Filelist, $List[$i], "Url" & $Number, "")
        Local $path = IniRead($Filelist, $List[$i], "File" & $Number, "")
        If Not FileExists($path) Then
            InetGet($url, $path)
        Else
            Sleep(10)
        EndIf
        $Number = $Number + 1
    Next
EndFunc

Please help =/

Link to comment
Share on other sites

IniReadSection() returns a 2D array, so the first example was closer. But you are doing a FileExists() test on every key in the section, including the URLs. So maybe:

Func _Check()
    $Filelist = @ScriptDir & "\Filelist.bin"
    $List = IniReadSection($Filelist, "Files")
   
    For $i = 1 To $List[0][0]
        If StringInStr($List[$i][0], "FilePath") Then
            If FileExists($List[$i][1]) Then
                Sleep(100)
            Else
                InetGet($List[$i + 1][1], $List[$i][1])
            Endif
        EndIf
    Next
EndFunc

More error checking would be good, but that's the basic idea.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well i tryed this out. This function was for updating =) But i got 1 more prob. Code :

Func _Update()
    Local $Filelist = @ScriptDir & "\Filelist.bin"
    Local $List = IniReadSection($Filelist, "Files")
  
    For $i = 1 To $List[0][0]
        If StringInStr($List[$i][0], "File") Then
            If Not FileExists($List[$i][1]) Then
                Sleep(100)
                InetGet($List[$i + 1][1], $List[$i][1])
                If @error Then
                    GUICtrlSetData($Label1, "Error while downloading ...")
                EndIf
            Else
                Return
            Endif
            ;Local $Size = FileGetSize($List[$i][1])
            ;Local $OSize = InetGetSize($List[$i + 1][1])
            If Not FileGetSize($List[$i][1]) = InetGetSize($List[$i + 1][1]) Then
                Sleep(100)
                InetGet($List[$i + 1][1], $List[$i][1])
                If @error Then
                    GUICtrlSetData($Label1, "Error while downloading ...")
                EndIf
            EndIf
        EndIf
    Next
    Return
EndFunc

When there are no files in folder, it downloads them and if files exist but has another size then it deletes old ones and downloads new ones.

But it dont want to work. It downloading when files are not exist but its not updaiting when files have different size ... any ideas ?

Edited by Demon777
Link to comment
Share on other sites

Well i tryed this out. This function was for updating =) But i got 1 more prob. Code :

; ...<snip>
            If Not FileGetSize($List[$i][1]) = InetGetSize($List[$i + 1][1]) Then
; ...<snip>

When there are no files in folder, it downloads them and if files exist but has another size then it deletes old ones and downloads new ones.

But it dont want to work. It downloading when files are not exist but its not updaiting when files have different size ... any ideas ?

You have to carefully consider order of operations in a statement like that. The operator NOT is first before all others (see Operators section in help file). So you have the equivalent of this:
If ( NOT FileGetSize($List[$i][1]) ) = InetGetSize($List[$i + 1][1]) Then

You could group with parens:

If NOT ( FileGetSize($List[$i][1]) = InetGetSize($List[$i + 1][1]) ) Then

But it is much easier to use the correct <> operator:

If FileGetSize($List[$i][1]) <> InetGetSize($List[$i + 1][1]) Then

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...