Jump to content

Question about FileWrite


Delai
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 months later...

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
Link to comment
Share on other sites

  • Moderators

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))

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

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