Jump to content

Increase numbers in txt file


Yuljup
 Share

Go to solution Solved by jdelaney,

Recommended Posts

Hi,

I have an xml file I would like to edit.

The function I'm looking for is to increase a number in the code... And I would like the number to increase by adding 1 every time the script runs.

For example:

--------------------------

<code in here: v="14">

   <some more code>

<end of code>

--------------------------

The number 14 should be 15 after the script is run... Then 16, and so on...

 

What I have so far:

$szFile = "C:\Service\Custom.xml"


$szText = FileRead($szFile,FileGetSize($szFile))
$szText = StringReplace($szText, "Something in here", "Something else in here")
FileDelete($szFile)
FileWrite($szFile,$szText)
Edited by Yuljup
Link to comment
Share on other sites

If you want to turn the 14 into a 15 or just add one each time it will make it easier on yourself to read the number from the file, then change it to an int and add 1 using:

Number()

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Or

Int()

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Explain more.

What is the file type for start.

EDIT:

Never mind I see it's xml.

There is code in example forum to deal with xml files, with plenty of example.

EDIT2:

for example

'?do=embed' frameborder='0' data-embedContent>>

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I would check out the link JohnOne gave you, but here is a small example of something similar (untested):

Local $fileOpen, $fileRead, $findString, _
        $splitString, $num, $replacedString, _
        $szFile = "C:\Service\Custom.xml"

$fileOpen = FileOpen($szFile)
$fileRead = FileRead($fileOpen)

$findString = StringInStr($fileRead, 'v="')
$splitString = StringMid($fileRead, $findString + 2, 3) ; not taking into account 3 digit #'s such as 100, 200, etc

$num = Int($splitString)

$replacedString = StringReplace($fileRead, String($num - 1), String($num))

FileWrite($fileOpen, $replacedString)

FileClose($fileOpen)
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Solution

xmldom...the filecreate is just used to have the xml...you won't need that, or the filewrite.:

#include <File.au3>
$sFileText = "<code v=""14""><somemorecode /></code>"
_FileCreate("test.xml")
FileWrite("test.xml",$sFileText)
Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.load("test.xml")
$oV = $oXML.SelectSingleNode("//code/@v")
$oV.text = Int($oV.text) + 1
ConsoleWrite($oV.text & @CRLF)
$oXML.save("test.xml")
ConsoleWrite(FileRead("test.xml") & @CRLF)

output:

15
<code v="15"><somemorecode/></code>

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks for all your help, guys.

jdelaney: This is close to what I need. But how do I switch out the following part of your code with something that looks for any number, not just 14?

I would like the script to be run on an automated schedule, and not have to change the script every time.

 

$sFileText = "<code v=""14""><somemorecode /></code>"

 

Link to comment
Share on other sites

$sFileText = "<code v=""14""><somemorecode /></code>"

Jdelaney's code doesn't look for that, it only used that in an example file.

The later code looks for whatever number is in the 'code v' section of your document.

Once you've run the code once, comment out the first 3 lines after the #include line, then run it again ... and again.

You should see that the number increments each time.

Or just try it with your xml file, after putting in the replacement path for "test.xml" for it.

The only possible issue, is if your number is not embedded in the same formatted text - <code v="

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Brilliant! Thanks for clarifying this for me, TheSaints! And thank you again, jdelaney!

This is exactly what I needed.

If anyone is wondering or if anyone meets the same problem as I did;

This is to fix an issue where Enterprise Mode in IE11 stops working in a Citrix environment with Citrix User Profile Management.

I noticed that updating the xml file used by Enterprise Mode corrects the issue when it stops working.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...