ShupDogg Posted February 17, 2021 Share Posted February 17, 2021 I am looking for a script to replace the string in 2 different files types. I have .hod files and .ws files. These are AS/400 Session file types. If you open the files with a text editor you can change the Host they are connecting to. I need to change if needed to a Standard Host name. .HOD file has a line host=X.X.X.X or something of the sort and I need it to be host=DNSName .WS file has a line HostName=X.X.X.X and needs to be HostName=DNSName It would be nice to be able to run this script silently on the PC if running with a switch (can do with software deployment) and if a person wanted to run it manually they would get a pop-up on how many it changed. The bad thing is these files could be in quite a few different places on the PC. If I could put in the script the most common places to look for the files that would be good to. I also just found out that if the session is open and you change the string, when you close the session it changes the string back to what it was. I guess maybe error with "sessions need to be closed" if there is a certain exe running. Thank you in advanced for any help you can provide. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2021 Moderators Share Posted February 17, 2021 Moved to the appropriate forum. Moderation Team ShupDogg 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nine Posted February 17, 2021 Share Posted February 17, 2021 (edited) Welcome to the AutoIt forum. Normally you should come up with a basic script so we can be able to help in solving issues you are facing. BUT since it is your first time here and it is such an easy script, it would take me longer to explain what you should be doing than giving a frame that you could work on. Next time, please, make an effort to create a runable script that we actually can execute. If you still need help, provide example files that you want to modify. #include <File.au3> Local $aRoot[] = ["c:\Apps\Temp\","c:\users\" & @UserName & "AppData\local\"] ; add as much root folders as you want here Local $aFile, $sFile, $sContent, $sDrive, $sDir, $sFileName, $sExtension For $sFolder in $aRoot ConsoleWrite ($sFolder & @CRLF) $aFile = _FileListToArrayRec($sFolder, "*.HOD;*.WS", $FLTAR_FILES, $FLTAR_RECUR, Default, $FLTAR_FULLPATH) If @error Then ContinueLoop For $i = 1 To $aFile[0] $sFile = $aFile[$i] $sContent = FileRead($sFile) _PathSplit($sFile, $sDrive, $sDir, $sFileName, $sExtension) If $sExtension = ".HOD" Then $sContent = StringRegExpReplace($sContent, "(?is)(Host=)(\d+\.\d+\.\d+\.\d+)","$1DNSNAME") Else $sContent = StringRegExpReplace($sContent, "(?is)(HostName=)(\d+\.\d+\.\d+\.\d+)","$1DNSNAME") EndIf FileWrite($sDrive & $sDir & "New_" & $sFileName & $sExtension, $sContent) Next Next Edited February 17, 2021 by Nine ShupDogg 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ShupDogg Posted February 23, 2021 Author Share Posted February 23, 2021 Melba23, Thank you for moving it to the appropriate forum. Nine, Thank you so much for the example script. I have been searching for a script for a few weeks now. I am usually really good at coming up with an idea but don't have the syntax knowledge to put it together. I will work with this and let you know how I come out. Again Thank you! Link to comment Share on other sites More sharing options...
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