Jump to content

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

×
×
  • Create New...