Jump to content

Read and Overwrite


Recommended Posts

Hi Everyone,

i've a (maybe simple) problem and may just need a slap from anyone of you ;)

I get crazy with this simple part of my Script..:

$diff1 = "24"

$hours = FileRead("C:\Users\sx40211\desktop\Header\Stundencounter.txt")

$counted = FileReadLine("C:\Users\sx40211\desktop\Header\Stundencounter.txt", 1)

$Counter = FileOpen("C:\Users\sx40211\desktop\Header\Stundencounter.txt", 2)

FileWriteLine($Counter, StringReplace($hours, $counted, $counted+$diff1))

FileClose($Counter)

$datefile = FileRead("C:\Users\sx40211\desktop\Header\Datum.txt")

$altdatum = FileReadLine("C:\Users\sx40211\destktop\Header\Datum.txt", 1)

FileClose($datefile)

$newdatum = FileOpen("C:\Users\sx40211\desktop\Header\Datum.txt", 2)

FileWriteLine($newdatum, StringReplace($datefile, $altdatum, $date8))

FileClose($newdatum)

Maybe you can see what i try to do... the first part of the script is working well.. but the second part don't do what i whant him to do ^^

I would like to overwrite some text in a specific text-file.. but insteed of overwriting the text with the value wich hase $date8 given, he just overwrite it with empty letters.. or just delete it, call it what ever you want ^^

can anyone tell me what i'm doing wrong?

Thank you very much in advance!

Link to comment
Share on other sites

Where did u set the var $date8? what does that correspond to?

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Do some troubleshooting by seeing what $altdatum contains before doing the FileWriteLine. Also, you're closing a file with FileClose(datefile) that was never opened, so it's not doing what you think it is.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Unless you know for sure that it read it, you can't say with any certainty that the information you're trying to write back to the file is there to begin with. In SciTE, click on the variable name, then hit ALT-D to get a consolewrite line (assuming you have the full Scite4AutoIt3 installed). This will tell you what $altdatum has in it, in the console of SciTE.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I think i get what you're after, u want the script to read a file, change a certain line with some text and leave the rest, huh?

$ReplaceWith = "SomeText"
$ReplaceLine = "1"
$FOpen = FileOpen(@DesktopDir&"\Data.txt")
$WholeFile = FileRead($FOpen)
MsgBox(64, 'File Contains:', $WholeFile)
$FRLine = FileReadLine($FOpen, $ReplaceLine)
MsgBox(64, 'I Read This:', $FRLine)
FileClose($FOpen)
$FWOpen = FileOpen(@DesktopDir&"\Data.txt", 2)
$FWOpen = FileWriteLine($FWOpen, StringReplace($WholeFile, $FRLine, $ReplaceWith))
FileClose($FWOpen)

First 2 variables have the parameters to change, if you have doubts, we're here.

EDIT: Simplified the code.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hi Careca,

Thanks a lot, i think this is realy this i looked for! My prob was, that i did not really know: do i have to open and close the file before writing, or do i have to close the file after writing.. maybe i discript my intention a bit more difficult as the whole problem itself ^^

I'll take a try and let you know! Thanks man!

Link to comment
Share on other sites

About your example... you define the Variable $FWOpen in the second Part as the WriteLine.. do i have do define it as a Variable or could i have it as a prompt?

Like:

$FWOpen = FileOpen(@DesktopDir&"Data.txt", 2)

FileWriteLine($FWOpen, StringReplace($WholeFile, $FRLine, $ReplaceWith))

FileClose($FWOpen)

I the case i have to define this as a viriable, i have to use this variable in the following script to start the task i think.. but i wouldn't realy know how i can say: Start this variable(Task)

Thanks a lot!

Link to comment
Share on other sites

Glad i could help and that you got it sorted out. :)

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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