Jump to content

Recommended Posts

Rammanan

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

@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

@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

@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

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

    • DynamicRookie
      By DynamicRookie
      Hey There!
       
      So, what i need to do is an app that can read text in a image (I.e. a png that has text saying "This is a png" and return the text to a variable)
      I'm pretty much a newbie on AutoIt, my purpose is doing that but i don't know any function that can

      Any help is much appreciated
    • santoshM
      By santoshM
      How can i exit from a procedure in auto
      Func test() if x=o then     return endif endFunc  
    • Valnurat
      By Valnurat
      Hi
      Small question.
      I trying to find all index in an array with value higher than 7.
      How can that be possible?
    • TrashBoat
      By TrashBoat
      Could someone help me create or give an idea of how to do a incrementing for loop that would do this: https://i.imgur.com/YFUt47H.gifv
      I'm having a hard time figuring it out :S
    • msd1994
      By msd1994
      I have a script that just adds some keyboard shortcuts for things like displaying the current song and artist, moving the window to the side so it won't pop up in my way, and play/pause, next song, previous song (these are the only 3 to still work since they don't need the window handle.)
      In some update recently, Spotify's window class swapped from "[CLASS:SpotifyMainWindow]" to "[CLASS:Chrome_WidgetWin_0]". Using the new class in my controls doesn't seem to work, I've tried getting the window handle from the process handle (_GetHwndFromPID($PID)) but that seems to fail as well.
      Does anybody have some idea of a way I could get this script working again?
       
      edit: seems like discord has the same window class name, so could be some issue with this? Still not sure of a way to solve the issue though, I added a function to get the handle of the active window and can just use that now, but it was able to find it on its own before on spotify startup or script startup which would be preferred.
       
      Thanks!
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.