Jump to content

convert text file to autoit script


 Share

Recommended Posts

hi,

i want to convert this

Important (Please Read)
this file is very important.

A > Lin1 > Just Test
Some text > Lin2 > B
C > Lin3 > Just Test
Some text > Lin4 > D
E > Lin5 > Just Test
Some text > Lin6 > F
G > Lin7 > Just Test
Some text > Lin8 > H
I > Lin9 > Just Test
Some text > Lin0 > J

to this

Global $path = @ScriptDir & "\"
Global $name = "Convert.txt"
If Not FileExists($path & $name) Then
    FileWrite($path & $name, "; Important (Please Read)" & @CRLF & "this file is very important.")
    FileWrite($path & $name, "")
    FileWriteLine($path & $name, "A > Lin1 > Just Test")
    FileWriteLine($path & $name, "Some text > Lin2 > B")
    FileWriteLine($path & $name, "C > Lin3 > Just Test")
    FileWriteLine($path & $name, "Some text > Lin4 > D")
    FileWriteLine($path & $name, "E > Lin5 > Just Test")
    FileWriteLine($path & $name, "Some text > Lin6 > F")
    FileWriteLine($path & $name, "G > Lin7 > Just Test")
    FileWriteLine($path & $name, "Some text > Lin8 > H")
    FileWriteLine($path & $name, "I > Lin9 > Just Test")
    FileWriteLine($path & $name, "Some text > Lin0 > J")
EndIf

Convert a *.txt file to a script which will write the text file.

how?

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.
Link to comment
Share on other sites

Func _Text2AutoIt($Au3file, $File2Write, $text)
;$file is the file to write to
$hFile = Fileopen($Au3file, 2);erase previous content
$Split = StringSplit($text, @CRLF)
For $i = 1 to $Split[0]
Filewriteline($hFile, 'FileWriteLine("' & $File2Write & '","' & $split[$i] & @crlf & '")')
Next
Fileclose($hFile)
EndFunc

With some minor changes you can fit it to your needs :)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

#include <File.au3>

Dim $aRows
Dim $inFile = "test.txt"
Dim $outFile = "test.au3"

_FileReadToArray($inFile, $aRows)

$hOutFile = FileOpen($outFile,2)

FileWriteLine('Global $path = @ScriptDir & "\"')
FileWriteLine('Global $name = "Convert.txt"')
FileWriteLine('If Not FileExists($path & $name) Then')

For $X = 1 to $aRows[0]
    FileWriteLine($hOutFile,'FileWriteLine($path & $name, ' & $aRows[$X] & ')')
Next

FileWriteLine('EndIf')
FileClose($hOutFile)

Edited by weaponx
Link to comment
Share on other sites

#include <File.au3>

Dim $aRows
Dim $inFile = "test.txt"
Dim $outFile = "test.au3"

_FileReadToArray($inFile, $aRows)

$hOutFile = FileOpen($outFile,2)

FileWriteLine('Global $path = @ScriptDir & "\"')
FileWriteLine('Global $name = "Convert.txt"')
FileWriteLine('If Not FileExists($path & $name) Then')

For $X = 1 to $aRows[0]
    FileWriteLine($hOutFile,'FileWriteLine($path & $name, ' & $aRows[$X] & ')')
Next

FileWriteLine('EndIf')
FileClose($hOutFile)
Better :)

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

#include <File.au3>

Dim $aRows
Dim $inFile = "test.txt"
Dim $outFile = "test.au3"

_FileReadToArray($inFile, $aRows)

$hOutFile = FileOpen($outFile,2)

FileWriteLine('Global $path = @ScriptDir & "\"')
FileWriteLine('Global $name = "Convert.txt"')
FileWriteLine('If Not FileExists($path & $name) Then')

For $X = 1 to $aRows[0]
    FileWriteLine($hOutFile,'FileWriteLine($path & $name, ' & $aRows[$X] & ')')
Next

FileWriteLine('EndIf')
FileClose($hOutFile)
thanks but

2.au3 (11) : ==> Incorrect number of parameters in function call.:

FileWriteLine('Global $path = @ScriptDir & "\"')

^ ERROR

after changing it to

FileWriteLine($hOutFile, 'Global $path = @ScriptDir & "\"')

result is not good.

Edited by SoftVoile
Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.
Link to comment
Share on other sites

have you looked at the function reference on the help file ?

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Well considering I didn't actually test the code, you could have done more investigating...

#include <File.au3>

Dim $aRows
Dim $inFile = "test.txt"
Dim $outFile = "test.au3"

If NOT FileExists($inFile) Then
    MsgBox(0,"Input file not found", $inFile)
    Exit
EndIf

_FileReadToArray($inFile, $aRows)

$hOutFile = FileOpen($outFile,2)

FileWriteLine($hOutFile,'Global $path = @ScriptDir & "\"')
FileWriteLine($hOutFile,'Global $name = "Convert.txt"')
FileWriteLine($hOutFile,'If Not FileExists($path & $name) Then')

For $X = 1 to $aRows[0]
    FileWriteLine($hOutFile,'FileWriteLine($path & $name, "' & $aRows[$X] & '")')
Next

FileWriteLine($hOutFile,'EndIf')
FileClose($hOutFile)
Link to comment
Share on other sites

Well considering I didn't actually test the code, you could have done more investigating...

#include <File.au3>

Dim $aRows
Dim $inFile = "test.txt"
Dim $outFile = "test.au3"

If NOT FileExists($inFile) Then
    MsgBox(0,"Input file not found", $inFile)
    Exit
EndIf

_FileReadToArray($inFile, $aRows)

$hOutFile = FileOpen($outFile,2)

FileWriteLine($hOutFile,'Global $path = @ScriptDir & "\"')
FileWriteLine($hOutFile,'Global $name = "Convert.txt"')
FileWriteLine($hOutFile,'If Not FileExists($path & $name) Then')

For $X = 1 to $aRows[0]
    FileWriteLine($hOutFile,'FileWriteLine($path & $name, "' & $aRows[$X] & '")')
Next

FileWriteLine($hOutFile,'EndIf')
FileClose($hOutFile)
now it's fine, thanks a lot for writing,testing and posting script.

your helping efforts are really able to be appreciated.

thanks once again...

Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them.
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...