Sign in to follow this  
Followers 0
hrumus

filereading

7 posts in this topic

Hai. I have a file filled with country codes.. like .com is for usa domain (usually) and i want this file to be copied into an other file i got.

it has to post it like this

INSERT INTO `countries` VALUES ('COM', 'USA');

INSERT INTO `countries` VALUES ('DE', 'DEUTSCHLAND');

and so on.

i tried alot of things but i just dont copy it right into the new file

please help me

i attached the original file with all the countries and countrycodes in.

countries.txt

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hai. I have a file filled with country codes.. like .com is for usa domain (usually) and i want this file to be copied into an other file i got.

it has to post it like this

INSERT INTO `countries` VALUES ('COM', 'USA');

INSERT INTO `countries` VALUES ('DE', 'DEUTSCHLAND');

and so on.

i tried alot of things but i just dont copy it right into the new file

please help me

i attached the original file with all the countries and countrycodes in.

Post an example of what you have tried so we can get a better handle on what it is you are trying to do here. Right now I don't know if you are trying to replace text in the original file, create a new text file or write this information to an INI file. maybe even something entirely different.

Perhaps all you want is the order of each line changed

example

cf  Central African Republic

becomes

('cf', 'Central African Republic')

If you want each word like Germany translated to the native tongue then you have a lot of work ahead of you. Edited by GEOSoft

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!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

sorry for not being precise enough.. heres my most working script (it doesnt give me and error)

FileOpen("countries.txt",0)
While 1
$readden = FileReadLine("countries.txt")
if @error = -1 Then ExitLoop
filewrite("countries.sql",$readden)
WEnd

but it just outputs alot of Central African Republic in my file :)

and no translation is needed.. i just wrote DEUTSCHLAND because i thought thats how to spell it

Edited by hrumus

Share this post


Link to post
Share on other sites

Try this

$hOpen = FileOpen("countries.txt", 0)
While 1
    $readden = FileReadLine($hOpen)
    If @error = -1 Then ExitLoop
    FileWrite("countries.sql", $readden)
WEnd
FileClose($hOpen)oÝ÷ Úí+ºÚ"µÍÈYÛÝ[YËÜ[^ÝÈ[[ÛÝ[YËÝÚÙHÜX]HÛÝ[YËÜ[[UÜ]J ][ÝØÛÝ[YËÜ[   ][ÝË[TXY
    ][ÝØÛÝ[YË  ][ÝÊJ

Share this post


Link to post
Share on other sites

thanks. but now i just need it to print in the correct format. like this

INSERT INTO `countries` VALUES ('COM', 'USA');

INSERT INTO `countries` VALUES ('DE', 'GERMANY'); (thanks for the correction GEOSoft)

can any1 help me how to do that ?

Share this post


Link to post
Share on other sites

Something like this

$file = "countries.sql"
$hOpen = FileOpen("countries.txt", 0)
$sTxt = ""
While 1
    $readden = FileReadLine($hOpen)
    If @error = -1 Then ExitLoop
    $aRd = StringSplit($readden, @TAB)
    $sTxt &= "INSERT INTO `countries` VALUES ('" & $aRd[1] & "', '" & $aRd[2] & "');" & @CRLF
WEnd
FileOpen($file, 2)  ; write erase, comment out to append
FileWrite($file, $sTxt)
FileClose($hOpen)
FileClose($file)

Share this post


Link to post
Share on other sites

HOLY CRAP! UR A GENIUS!!! THANKS SO MUCH :)

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