Rammanan Posted March 21, 2018 Posted March 21, 2018 (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 March 21, 2018 by Rammanan
KickStarter15 Posted March 21, 2018 Posted March 21, 2018 (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 March 21, 2018 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.
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 @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
KickStarter15 Posted March 21, 2018 Posted March 21, 2018 @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.
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 (edited) @KickStarter15 My $file is a file. $file = ("C:\New folder\macadd.txt") After test ur script still i get false. Edited March 21, 2018 by Rammanan
Subz Posted March 21, 2018 Posted March 21, 2018 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
KickStarter15 Posted March 21, 2018 Posted March 21, 2018 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.
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 (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 March 21, 2018 by Rammanan
Subz Posted March 21, 2018 Posted March 21, 2018 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)
Subz Posted March 21, 2018 Posted March 21, 2018 (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 March 21, 2018 by Subz
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 Thank you so much for the BIG help @Subz. It work good.
KickStarter15 Posted March 21, 2018 Posted March 21, 2018 As always Subz. One of the best. Rammanan 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.
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 @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.
Subz Posted March 21, 2018 Posted March 21, 2018 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
Rammanan Posted March 21, 2018 Author Posted March 21, 2018 @Subz Thanks so much . above script work perfect.
Rammanan Posted March 22, 2018 Author Posted March 22, 2018 (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 March 22, 2018 by Rammanan
Subz Posted March 22, 2018 Posted March 22, 2018 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)
Rammanan Posted March 23, 2018 Author Posted March 23, 2018 @Subz Above script work fine to me. Thanks u so much.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now