Jump to content

Can Auto It Edit txt files?


 Share

Recommended Posts

i just want to know how to make it so autoit would edit a bunch of "alike" files

this is what is within the txt file

Before:

objShell.SendKeys " ipod{TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}":Wscript.Sleep 100

i want move the word after ".Sendkeys" and before "{TAB}" and place it right before ":Wscript.Sleep"

final product would look like this

After:

objShell.SendKeys " {TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}ipod":Wscript.Sleep 100

Link to comment
Share on other sites

i just want to know how to make it so autoit would edit a bunch of "alike" files

this is what is within the txt file

Before:

objShell.SendKeys " ipod{TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}":Wscript.Sleep 100

i want move the word after ".Sendkeys" and before "{TAB}" and place it right before ":Wscript.Sleep"

final product would look like this

After:

objShell.SendKeys " {TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}ipod":Wscript.Sleep 100

Look at the help file under FileOpen() and FileRead() and then look at the String manipulation functions.

[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

  • Moderators

Hi,... i tried finding how to cut out the string and inserting it where i wanted but couldnt...any help?

Sure...

In the help file there are functions that start with String

You'd look at those, the steps would look something like:

1. Read File To String

$sRead = FileRead("FileName")

2. Use one of the String Functions to edit if you know where you want.

Example, I know I want the 3rd Character of that string.

$sString = StringMid($sRead, 3, 1);Give me only 1 Char, and make sure it's the 3rd on of the string

Let's say I want to find a specific string and It's Position.

$nFindPosition = StringInStr($sRead, "{TAB}")

If $nFindPosition Then ;If it's not found, $nFindPoition will be 0, if it is found, it will be the position found at.

$sTrimLeft = StringTrimLeft($sRead, $nFindPosition);Now $sTrimLeft will be from where you found {TAB} at on, trimming out everything before it.

The list goes on and on.

GL

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

thx for the reply, ill try get started right away

Also look up _FileReadToArray() in user defined functions

Read each element to see if it contains

objShell.SendKeys " ipod{

Then Use StringReplace() twice

$oFldr = <file path>
$File = $oFldr & "\My_File.vbs"
$sRecs = ""
_FileReadToArray($File, $sRecs)
$oFile = FileOpen($File, 2)
For $I = 1 To Ubound($sRecs) -1
$sRecs[$I] = StringReplace($sRecs[$I], 'objShell.SendKeys " ipod{', 'objShell.SendKeys "{')
$sRecs[$I] = StringReplace($sRecs[$I], '}":Wscript.Sleep', '}ipod":Wscript.Sleep')
FileWriteLine($oFile, $sRecs[$I])
Next
FileClose($oFile)

<file path> must be replaced with the actual path to the files

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

Since I think StringRegExp should be used here, I'll give you an example of how I would approach it:

$sString = 'objShell.SendKeys " ipod{TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}":Wscript.Sleep 100'
$aSRE = StringRegExp($sString, 'objShell.SendKeys " (.*?)\{TAB\}', 1)
If IsArray($aSRE) Then
    $sString = StringRegExpReplace($sString,  'objShell.SendKeys " (.*?)\{TAB\}',  'objShell.SendKeys " {TAB}')
    $sString = StringRegExpReplace($sString, '":Wscript.Sleep 100', $aSRE[0] & '":Wscript.Sleep 100')
EndIf
MsgBox(0,0,$sString)
See if you can follow that.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

How do i get the files names of files selected from FileSaveDialog function??

and... is it possible to use that the also add multiple items to GUICtrlCreateListViewItem

Put it in a variable as the help file example shows. Then pass the variable to FileRead.

I think you need to get the basics down before you go messing with GUI's.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Smoke N's approach is very elegant. Having little experience with regular expressions I would do it thus:

$str = "objShell.SendKeys "" ipod{TAB}+{TAB}{RIGHT 1}save{TAB}+{TAB}{RIGHT 2}lien{TAB}+{TAB}{RIGHT 3}errs{TAB}+{TAB}{RIGHT 4}{TAB}royal{TAB}+{TAB}{RIGHT 1}ohara{TAB}+{TAB}{RIGHT 2}fired{TAB}"":Wscript.Sleep 100"

; or read from file: 
;$str = FileRead ($infile)

$l = StringInStr ($str, "{TAB}")
$l1 = StringLen ("objShell.SendKeys "" ")
$l2 = StringLen (""":Wscript.Sleep 100")
; Remark: if the previous values are constant ie the strings do not change then substitute the constants in the next line $l1 =20, $l2 =19

$nstr = StringLeft ($str,$l1) & StringTrimRight (StringMid ($str, $l), $l2) & StringMid ($str, $l1, $l-$l1) & StringRight ($str,$l2)
MsgBox(0, "Subtitles", $str)
;FileDelete ($outfile);needed because FileWrite  "appends" to old contents
;FileWrite  ($outfile, $nstr)
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...