Sign in to follow this  
Followers 0
xcaliber13

Powershell to AutoIt Help

5 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Maybe StringSplit() then _FileWriteFromArray()

Loop your array inserting a carriage return every 1024 characters as determined by the split. 

Share this post


Link to post
Share on other sites

#5 ·  Posted

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0