Sign in to follow this  
Followers 0
Delai

Question about FileWrite

8 posts in this topic

#1 ·  Posted (edited)

Hi men i want to change a string in a text, but whitout success, i think the problem is the extension of the text file (.tpr) because the file it writes me contains only "Video-Hol.tpr" and not the text changed, (I think it does not read the file well), here is my script:

$search_Project = FileFindFirstFile(".\Scripts\Plantilla\*.tpr")

While 1

$Project = FileFindNextFile($search_Project)

If @error Then ExitLoop

$Project_String = StringSplit( $Project , "-" & "." )

$Project_Text = FileRead($Project,FileGetSize($Project))

$Project_Text = StringReplace ($Project, $Project_String[2], "Hol")

FileWrite(".\Scripts\Video-" & $Project_String[2] & ".tpr",$Project_Text)

WEnd

Edited by Delai

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I can't understand your english or your code. It looks like you've got a potential logic error buried in your renaming function. When you split the array it may not be what you are expecting , depending on the file it's grabbed.

It would also be a good idea to familiarize yourself with filehandles if these files are larger than a couple of kb.

Test your stringsplit to ensure that the $project_string array is what you expect.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Video_Capi.txtI have found the problem, it tries to read the archive .tpr but it seems not be able to read it because it has characters, i have attached one example.

I have changed the extension of the archive because it does not let me to upload it, so the file is:

Video-Capi.tpr

I have tested the $project_String and is right.

Edited by Delai

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have tried but without success and finally i decide to try with the simple script that i have copied from here (Forum), and only it works with a normal file, but it does not work with the file generated by a program, it creates the file but only with a character. I have attached the file like as it has generated. Any help please

http://rapidshare.com/files/17875417/Video-Capitulo.tpr.html

$szFile = "Video-Capitulo.tpr"
$szText = FileRead($szFile,FileGetSize($szFile))
$szText = StringReplace($szText, "Video-Capitulo", "Video-Prueba")
FileDelete($szFile)
FileWrite($szFile,$szText)
Edited by Delai

Share this post


Link to post
Share on other sites

Anyone would help me please

Thanks very much

Share this post


Link to post
Share on other sites

Please, is there anybody who can help me please?

Thank you very much

Share this post


Link to post
Share on other sites

Try reading the file to hex first:

$sString = Hex(BinaryString(FileRead('FileName')))
$sHexToFind = Hex(BinaryString('Video-Capitulo'))
$sHexToReplaceWith = Hex(BinaryString('Video-Prueba'))
$sString = StringReplace($sString, $sHexToFind, $sHexToReplaceWith)
FileWrite('OutFileLocation', BinaryString('0x' & $sString))

[center]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.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thank you very much @SmOke_N.

I will try it and i will inform you later.

Thanks again.

EDIT:

I have tried it in an example, and it seems to work like a charm, i will implement it in my script.

Thank you very much again @SmOke_N for your appreciated help

Edited by Delai

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