Jump to content

Powershell to AutoIt Help


Recommended Posts

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

  • Moderators

@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 (:x) 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

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

 

Link to comment
Share on other sites

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

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...