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

    • SharpDressedMan
      By SharpDressedMan
      I have an array of subarrays, eg:
      local $a[3] = [ 1, 2, 3 ] local $b[3] = [ 4, 5, 6 ] local $c[2] = [ $a, $b ] I can read read a subarray element of the array, as follows:
      local $c12 = ($c[1])[2] ; result: $c12 = 6 However, when I try to set a subarray element as follows, it fails:
      ($c[1])[2] = 12 ; this fails to set subarray element local $c12 = ($c[1])[2] ; result: $c12 = 6 How to set a subarray element ?
      Thanks
    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • KhalidAnsari
      By KhalidAnsari
      Hi,
      I need to automate Java application using AutoIt, I have refer forum for the same, as per forum I am using Java Access Bridge to finding control name. But could not set value to control. Below is my sample code 
      Send("#r")
      sleep(1500)
      Send("D:\javaapplication\javaapplication\Hello.jar{Enter}")
      WinActivate("Penjumlahan")
      sleep(1500)
      ControlSetText("Penjumlahan", "", "Name:  A :", "demo")
      Java Application and Java Ferret screen

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
×