Jump to content

Recommended Posts

Rammanan
Posted (edited)

Hi all, Below is my script,

Pls advise me if any wrong on that....File exit in location but the return -1.

FileOpen($file, 0)
   $line = FileReadLine($file)
   MsgBox(0,'',$line)
FileClose($file)

Local $aArray = _FileListToArrayRec($serverpath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
If @error Then
        MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
    Else
    ;_ArrayDisplay($aArray, "Sorted tree")
           Local $hSearch = FileFindFirstFile($line)
         MsgBox(0,'',$hSearch)

 

Edited by Rammanan

Share this post


Link to post
Share on other sites
KickStarter15
Posted (edited)

@Rammanan,

It means that there is no value found from your $file, check with the correct rendering on that and see help for more details. Also, make sure that your $serverpath ends with "\" to identify that "*|*.txt" that you are looking for.

Edited by KickStarter15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Rammanan

@KickStarter15

Thanks for reply. $file have value..Went i test with "FileExists" there have return true  but went i use "FileFindFirstFile" return is false. 

So my problem is on  "FileFindFirstFile". Pls advise

 

 

 

Share this post


Link to post
Share on other sites
KickStarter15

@Rammanan

1. In your FileReadLine($file) - output is valid for only line 1 reading.

2. Your _FileListToArrayRec() also a valid wherein all files found from $serverpath. However,

3. Your FileFindFirstFile($line) declares only the line found in your $file.

Q: Does your $file a path or a specific file. If file then it will surely returns false.

Try below and let me know what do you get after.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

$file = @ScriptDir & "\Test.Txt"
FileOpen($file, 0)
   $line = FileReadLine($file)
   MsgBox(0,'',$line)
FileClose($file)

Local $aArray = _FileListToArrayRec($serverpath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
If @error Then
        MsgBox($MB_SYSTEMMODAL, "Ooops!", "No files found")
Else
;~     _ArrayDisplay($aArray, "Sorted tree")
           Local $hSearch = FileFindFirstFile("*")
           While 1
            $sFileName = FileFindNextFile($hSearch)
            If @error Then ExitLoop
              $iResult = MsgBox(BitOR($MB_SYSTEMMODAL, $MB_OKCANCEL), "", "File: " & $sFileName)
            If $iResult <> $IDOK Then ExitLoop
            MsgBox(0,'',$hSearch)
         WEnd
EndIf

 


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Rammanan
Posted (edited)

@KickStarter15

My $file is a file.

$file  = ("C:\New folder\macadd.txt")

After test ur script still i get false.

 

 

 

 

Edited by Rammanan

Share this post


Link to post
Share on other sites
Subz

Not really sure what you're trying to do but can you try:

#include <Array.au3>
#include <File.au3>
Local $sServerPath = "\\Server\Share"
Local $sFileName = @ScriptDir & "\Filename.txt"
Local $sFileLine = FileReadLine($sFileName, 1)
    If $sFileLine = "" Then Exit MsgBox(32, "Error" "No data")
MsgBox(32,'',$sFileLine)

Local $aArray = _FileListToArrayRec($sServerPath, "*|*.txt", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_NOPATH)
    If @error Then Exit MsgBox(32, "Ooops!", "No files found")
Local $aSearch = _ArrayFindAll($aArray, $sFileName, 1)
    If @error Then Exit MsgBox(32, "Ooops!", "Search returned 0 results.")
For $i = 0 To UBound($aSearch) - 1
    MsgBox(32, "Found", $sFileLine & " found on line: " & $aSearch[$i])
Next

 

Share this post


Link to post
Share on other sites
KickStarter15
11 minutes ago, Rammanan said:

My $file is a file.

$file  = ("C:\New folder\macadd.txt")

I mean, the line inside that file.^_^

 

13 minutes ago, Rammanan said:

After test ur script still i get false.

What is the function that returns false, is it FileFindFirstFile() or _FileListToArrayRec().


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Rammanan
Posted (edited)

@KickStarter15 and @Subz

I trying to auto copy expired license from server to local PC once pop out the error on program running.
The license file name follow with PC mac address. Example "Clotho-E839353E05DC.lic".

Once pop out the error msg program will get mac add and save in .txt at c drive.
So my program need read the .txt file and search for same file name at server and copy to local.

 

Edited by Rammanan

Share this post


Link to post
Share on other sites
Subz

So you should be able to use something like:

#include <Array.au3>
#include <File.au3>
Local $sServerPath = "\\Server\Share"
Local $sFileCopy = False
Local $sFileName = @ScriptDir & "\Filename.txt"
Local $sFileLine = FileReadLine($sFileName, 1)
    If $sFileLine = "" Then Exit MsgBox(32, "Error", "No data")
MsgBox(32,'',$sFileLine)

Local $aArray = _FileListToArrayRec($sServerPath, "*|*.txt", 1, 1, 0, 2)
    If @error Then Exit MsgBox(32, "Ooops!", "No files found")
For $i = 1 To $aArray[0]
    If StringInStr($aArray[$i], $sFileLine) Then
        $sFileCopy = $aArray[$i]
        ExitLoop
    EndIf
Next
If $sFileCopy Then MsgBox(32, "File Found", $sFileCopy)

 

Share this post


Link to post
Share on other sites
Subz
Posted (edited)

Actually faster method:

#include <Array.au3>
#include <File.au3>
Local $sServerPath = "\\Server\Share"
Local $sFileName = @ScriptDir & "\Filename.txt"
Local $sFileLine = FileReadLine($sFileName, 1)
    If $sFileLine = "" Then Exit MsgBox(32, "Error", "No data")
MsgBox(32,'',$sFileLine)

Local $aArray = _FileListToArrayRec($sServerPath, "*|*.txt", 1, 0, 0, 2)
    If @error Then Exit MsgBox(32, "Ooops!", "No files found")
Local $iSearch = _ArraySearch($aArray, $sFileLine, 1, 0, 0, 1)
        If $iSearch = -1 Then Exit MsgBox(32, "File Not Found", "Search returned 0 results")
 MsgBox(32, "File Found", $aArray[$iSearch])

 

Edited by Subz

Share this post


Link to post
Share on other sites
Rammanan

Thank you so much for the BIG help @Subz.

It work good.

 

Share this post


Link to post
Share on other sites
KickStarter15

As always Subz. One of the best.:D

  • Like 1

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Rammanan

 

@KickStarter15 @Subz

Problem is on local PC have two IP address. So how to get mac address from IP connect to connect to server.                                                                 
Different with two IP is                                                                                                                                                                                                                                                                         Example : 192.168.30.111 and 192.168.0.2                                                                                                                                                                                                                                                    So i need get mac from 192.168.30.111 not from 192.168.0.2. This IP 192.168.0.2 same for all PC .
Please advice.

Share this post


Link to post
Share on other sites
Subz

Try something like:

#include <Array.au3>
Local $aMacAddress = _GetMacAddress()
_ArrayDisplay($aMacAddress)

Func _GetMacAddress($_sComputerName = @ComputerName)
    Local $aAdapter[1][2]
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\" & $_sComputerName & "\root\cimv2")
        If Not IsObj($objWMIService) Then Exit MsgBox(48, "Error", "Unable to connect to " & $_sComputerName)
    Local $oAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For $oAdapter in $oAdapters
        For $i = 0 To UBound($oAdapter.IPAddress) - 1
            ;~ Skip Null IPAddress
            If $oAdapter.IPAddress = Null Then ContinueLoop
            ;~ Skip IPAddress 192.168.0.2
            If $oAdapter.IPAddress($i) = "192.168.0.2" Then ContinueLoop
            ;~ Skip ipv6 IPAddresses
            If StringInStr($oAdapter.IPAddress($i), ":") Then ContinueLoop
            _ArrayAdd($aAdapter, $oAdapter.IPAddress($i) & "|" & $oAdapter.MacAddress)
        Next
    Next
    $aAdapter[0][0] = UBound($aAdapter) - 1
    Return $aAdapter
EndFunc

 

Share this post


Link to post
Share on other sites
Rammanan

@Subz

Thanks so much . above script work perfect.

 

Share this post


Link to post
Share on other sites
Rammanan
Posted (edited)
23 hours ago, Subz said:

 

 

 

Local $sFileLine = FileReadLine($LocalPath, 1)
    If $sFileLine = "" Then Exit MsgBox(32, "Error", "No File Create. Please contact your system administrator")
;MsgBox(32,'',$sFileLine)
FileClose($LocalPath)
Local $aArray = _FileListToArrayRec($sServerPath, "*|*.txt", 1, 1, 0, 2)
    If @error Then Exit MsgBox(32, "Error", "Cannot Found License in server. Please contact your system administrator ")
For $i = 1 To $aArray[0]
    If StringInStr($aArray[$i], $sFileLine) Then
        $sFileCopy = $aArray[$i]
        ExitLoop
    EndIf
Next
If $sFileCopy Then MsgBox(32, "File Found", $sFileCopy)
   FileCopy($sFileCopy,$localpath)
   FileMove($localpath,$sFileRenamed)

This script work good.But i cannot copy $sFilecopy to local.
Please advice.

Edited by Rammanan

Share this post


Link to post
Share on other sites
Subz

Can you change:

If $sFileCopy Then MsgBox(32, "File Found", $sFileCopy)

To

If $sFileCopy Then MsgBox(32, "Copy File", "Copy: " & $sFileCopy & " to " & $LocalPath)

Please let us know the result.

Also can you use the flag 9 for FileCopy example:

FileCopy($sFileCopy,$localpath, 9) ;~ $FC_OVERWRITE(1) + $FC_CREATEPATH(8)

 

Share this post


Link to post
Share on other sites
Rammanan

@Subz

Above script work fine to me. Thanks u so much. 

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

  • Similar Content

    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
×