xcaliber13 Posted July 10, 2017 Share Posted July 10, 2017 Hello, I have a powershell script that I would like to convert to Autoit but do not know how. Can I get some help please? Here is the Powershell: (gc X:\DEMOS\SIA\GuarantorTemp\RFGH_Demographics.txt) -replace ".{1024}" , "$&`r`n" | sc X:\DEMOS\SIA\GuarantorTemp\temp.txt Would I use StringReplace? or StringRegExpReplace? and what would be the correct syntax? Thank you Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 10, 2017 Moderators Share Posted July 10, 2017 @xcaliber13 There is no one-click "Powershell to AutoIt Conversion" button (wouldn't that be great!). As your PS script is getting the text of the original file, modifying and then outputting to a temp file, there are a couple of ways to go. You could look at _FileReadToArray and modify the file that way, or () read the file into a string and modify that way. One of our regex gurus will doubtless wander by and offer some suggestions as that is probably the fastest way to go (regex makes my eyes bleed, so I'm no help there). Just be aware it is not a simple syntax conversion like batch or vbs. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
junkew Posted July 11, 2017 Share Posted July 11, 2017 It looks like you want to add a cr lf every 1024 characters. Not sure if regex then is best solution. maybe just fileread(f,1024). I assume count is in characters and deals with the utf 8 encoding. https://www.autoitscript.com/autoit3/docs/functions/FileRead.htm FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 11, 2017 Share Posted July 11, 2017 Maybe StringSplit() then _FileWriteFromArray() Loop your array inserting a carriage return every 1024 characters as determined by the split. Link to comment Share on other sites More sharing options...
xcaliber13 Posted July 11, 2017 Author Share Posted July 11, 2017 Hey Guys, Thank you for the replies. With your help in pointing me in the right direction, I was able to find this little gem on these forums. Works GREAT! $str = FileRead("X:\Temp\YourFileName_.txt") $aWords = stringsplit($str , " " , 2) $sOut = "" $sRtn = "" for $i = 0 to ubound($aWords) - 2 $sOut &= $aWords[$i] & " " If stringlen($sOut) + stringlen($aWords[$i + 1]) >= 1024 Then $sRtn &= $sOut & @CRLF $sOut = "" EndIf next $sRtn = $sRtn & $aWords[ubound($aWords) - 1] msgbox(0, '' , $sRtn) FileWrite("X:\Temp\temp.txt", $sRtn) Again Thank you for your help 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