
coles
-
Posts
27 -
Joined
-
Last visited
Reputation Activity
-
coles reacted to rm4453 in {CAPSLOCK OFF} and {CAPSLOCK TOGGLE} not toggling caps lock off
https://www.autoitscript.com/forum/topic/10198-check-for-capslock-and-turn-off-so-lowercase/
-
coles reacted to Subz in [Solved] Help sort the directory tree under the level. _FileListToArrayRec()
Just my luck I only tested with 9 subfolders , you just need to turn the second value into a number, you could also use something like the following (probably could be written better) but works:
Local $aFolderPath, $x = 0 Local $aFolderPaths = _FileListToArrayRec(@ScriptDir, "*", 2, 1, 1, 2) _ArrayColInsert($aFolderPaths, 1) For $i = 1 To $aFolderPaths[0][0] $aFolderPath = StringSplit($aFolderPaths[$i][0], "\") If _ArraySearch($aFolderPaths, Number($aFolderPath[0] & "." & $x), 1, 0, 0, 0, 1, 1) > -1 Then $x += 1 $aFolderPaths[$i][1] = Number($aFolderPath[0] & "." & $x) Else $x = 0 While _ArraySearch($aFolderPaths, Number($aFolderPath[0] & "." & $x), 1, 0, 0, 0, 1, 1) > -1 $x += 1 WEnd $aFolderPaths[$i][1] = Number($aFolderPath[0] & "." & $x) EndIf Next _ArraySort($aFolderPaths, 1, 1, 0, 1) _ArrayDisplay($aFolderPaths)
-
coles reacted to jdelaney in Copying an XML file & Editing it and copying back
XPaths can be made contextual too. Say you are attempting to replace a node value, but it's inside another node with some known attribute. You would have to reinvent the wheel to determine which child node to update with just a string replace; where with an xpath, you can do something like this to get the proper node:
"//some/parent[@name='ThisIsTheParent']//child"
There could be a million parent nodes, with unique name attributes, and you would be able to grab the child in one swoop rather than create complicated regular expressions or loops. Of course, there is a bit to the learning curve in creating well formed xpaths as well.
-
coles reacted to Subz in Copying an XML file & Editing it and copying back
NP Either method should work fine, but using xml dom is targeted whereas if there is one character out with _ReplaceStringInFile it will fail.
Hope that made sense.
-
coles reacted to Subz in Copying an XML file & Editing it and copying back
You could use something like:
#include <_XMLDomWrapper.au3> Global $g_bSaveXml = False Global $g_sSample = @ScriptDir & "\sample.xml" Global $g_sRefNode = '//mobilePublicSafety/settings/customparam/ReferenceInformationAction' Global $g_sLocNode = '//mobilePublicSafety/settings/monitors/unitMonitor/grid/col[@dataFld="location"]' Global $g_sDGrNode = '//mobilePublicSafety/settings/monitors/unitMonitor/grid/col[@dataFld="dgroup"]' _XMLFileOpen($g_sSample, "", -1, False) Switch @error Case 1 MsgBox(16, "XML File Open Error", 'An error occurred while attempting to parse ' & @CRLF & $g_sSample) Exit Case 2 MsgBox(16, "XML File Open Error", 'No object was found while attempting to parse ' & @CRLF & $g_sSample) Exit EndSwitch Local $oRefNode = $objDoc.selectSingleNode($g_sRefNode) If IsObj($oRefNode) Then Local $sRefNode = $oRefNode.Text If $sRefNode = '"C:\Program Files\Internet Explorer\iexplore.exe" -k "c:\temp\temp.html"' Then $oRefNode.Text = '"C:\Program Files\Internet Explorer\iexplore.exe" -k "http:\\10.1.1.1\temp.html"' $g_bSaveXml = True EndIf EndIf Local $oLocNode = $objDoc.selectSingleNode($g_sLocNode) If IsObj($oLocNode) Then Local $sLocNode = $oLocNode.getAttribute("hidden") If $sLocNode = 1 Then $oLocNode.setAttribute("hidden", 0) $g_bSaveXml = True EndIf EndIf Local $oDGrNodeNode = $objDoc.selectSingleNode($g_sDGrNode) If IsObj($oDGrNodeNode) Then Local $sDRgNode = $oDGrNodeNode.getAttribute("hidden") If $sDRgNode = 0 Then $oDGrNodeNode.setAttribute("hidden", 1) $g_bSaveXml = True EndIf EndIf If $g_bSaveXml Then $objDoc.Save("sample.xml")
-
coles reacted to FrancescoDiMuro in Copying an XML file & Editing it and copying back
@coles
Could you post a sample "source" file and the result you are expecting from your script?
-
coles reacted to Subz in Copying an XML file & Editing it and copying back
If you check the number of lines of the target.xml are the same as the source.xml the _FileWriteToLine method should be fine, if they don't have the same number of lines just write to a network share that they aren't equal and you can check on these machines at a later stage. One note you would have to enclose those _FileWriteToLine lines with single quote ' at the beginning and end, as the lines you posted would error because of the internal double quotes. I would also backup the target.xml file before making changes, something like: FileCopy("<Path to Target.xml", @LocalAppDataDir & "\Backup\Target.xml", 8) that way you can restore the file if it fails.
Alternatively you could use XML Dom which I see you have included in your script and then just use _XMLSetAttrib to change the code.
-
coles reacted to mikell in what is the best way to compare files
#include <FileConstants.au3> If Number(FileGetTime("file1.txt", $FT_CREATED, 1)) > Number(FileGetTime("file2.txt", $FT_CREATED, 1)) Then _ Msgbox(0, "", "file2 is older than file1")
-
coles reacted to RickB75 in what is the best way to compare files
If you can use FileGetTime, you should be able to use
StringCompare ( "string1", "string2" [, casesense = 0] ) to compare the two strings.
-
-
coles reacted to jguinch in Counting and sorting duplicate lines
You are right Chimp. I edited my code : replace (? by (?=) in the 2nd regex (it was an oversight )
Thanks kylomas.
An similar code, but with a suppression of non duplicates lines at the beginning :
#Include <Array.au3> Local $iCount Local $sData = FileRead("data.txt") ; Eliminate non Duplicates Local $sDuplicates = StringRegExpReplace($sData, "(?s)(?:\A|\R)(\N+)(?=\R|\Z)(?!.*\R\1)", "") ; Duplicates in an Array (uniq rows) Local $aDuplicates = StringRegExp($sDuplicates, "(?s)(?:\A|\R)(\N+)(?=\R|\Z)(?!.*\1)", 3) Local $aResult[ UBound($aDuplicates)][2] For $i = 0 To UBound($aDuplicates) - 1 $aResult[$i][0] = $aDuplicates[$i] $aResult[$i][1] = UBound( StringRegExp($sData, "(?:\A|\R)\Q" & $aDuplicates[$i] & "\E(?=\R|\Z)", 3) ) Next _ArraySort($aResult, 1, 0, 0, 1) _ArrayDisplay($aResult) -
coles reacted to MichaelHB in [SOLVED]Count duplicates in an array
I belive this two links will help you achive your goal.
https://www.autoitscript.com/forum/topic/162076-search-an-array-for-duplicates/
https://www.autoitscript.com/forum/topic/165182-counting-and-sorting-duplicate-lines/
-
coles got a reaction from jincy in Help with a .bat file
Hi guys
i am looking for any help with a .bat file i am working on.
I am trying to extract few info from a file and dump into a text file (which i am able to do)
i am stuck at the part of deleting few text from the output file.
FINDSTR "\<vehicle>" c:\temp\1.xml >> result.txt
which outputs the result as <vehicle>100</vehicle>.
how can i delete <vehicle></vehicle> so that just 100 remains in the new file or new dump file
i was trying FINDSTR /v <vehicle> c:\temp\result.txt >> fleet.txt which is not working
any help will be really great full
Thank you
-
-
coles reacted to spudw2k in Merge two files
be careful. >> causes output to append to a file. > overwrites the contents of a file.
If you only use >> your file will grow, and grow, and grow. You should still use > for the netsh dump and >> for ipconfig to create a "fresh" file each run.
-
coles reacted to InunoTaishou in Something similar to FINDSTR
FileRead to read your file (store it in a variable)
StringInStr to search for the string in your variable
-
coles reacted to spudw2k in Merge two files
If you change the redirector for your ipconfig command to >> it will append the results to the text file.
netsh mbn show interface dump > c:\temp\a.txt
ipconfig /all >> c:\temp\a1.txt
This page may have some useful information for you regarding command line execution and output redirection.