I'm coding a mini application.
I need to store the date and time after each instance the code is run.
1. I can create and write to a new file every time.
2. Or... have one file and append to the end each time.
OK... so maybe the second option is the best?
Well... the thing is... I'm just worried about the code failing. It's bound to fail. It might be like 1 in 10,000 chance.
If the code failed and I got a corrupt file... then that would be a disaster.
Any thoughts?
I could maybe make backup copies after every 50 lines or something - but then I need to write more code to keep track.
Better keep simple? Doesn't really matter if I get a directory with 10,000 files.
(Or does it matter?)
Thanks.
Writing many small files vs adding to the end of a big file?
Re: Writing many small files vs adding to the end of a big file?
Maybe you can try to write the datetime to files at the first line.
Re: Writing many small files vs adding to the end of a big file?
even first line...
just worried something might happen and the program crashes and the file becomes corrupt
just worried something might happen and the program crashes and the file becomes corrupt
Re: Writing many small files vs adding to the end of a big file?
- You could have a main file and a backup file.
- The script checks the main file, if the main file is corrupted, it checks the backup file.
- When the script starts, it sets the contents of the main file, and confirms that it is not corrupted, it then does the same for the backup file, it then regularly updates the main file.
- If the main file becomes corrupted, you can use the backup file.
- The question is then that perhaps you want to update the backup file occasionally. If you do that, you should confirm that the main file is not corrupted prior to updating the backup file.
- The script checks the main file, if the main file is corrupted, it checks the backup file.
- When the script starts, it sets the contents of the main file, and confirms that it is not corrupted, it then does the same for the backup file, it then regularly updates the main file.
- If the main file becomes corrupted, you can use the backup file.
- The question is then that perhaps you want to update the backup file occasionally. If you do that, you should confirm that the main file is not corrupted prior to updating the backup file.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Writing many small files vs adding to the end of a big file?
hi jeeswg
how do you properly check /confirm that txt file is not corrupt?
is it just fileread or something else?
thank you in advance
how do you properly check /confirm that txt file is not corrupt?
is it just fileread or something else?
thank you in advance
Re: Writing many small files vs adding to the end of a big file?
- Yes, FileRead, and other checks like RegEx, and less-than/greater-than comparisons.
- There may be other ways, these are just some suggestions. I know that I've seen at least one program that stored info in files and a backup for each file.
- There may be other ways, these are just some suggestions. I know that I've seen at least one program that stored info in files and a backup for each file.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Writing many small files vs adding to the end of a big file?
If you are on win10 you can use file history backup ,it stores any change made to a file for later recovery if needed.I got a corrupt file
https://www.pcworld.com/article/2974385 ... ature.html
Re: Writing many small files vs adding to the end of a big file?
It might be easier to create a lock-file when you start your application and remove that one when you exit.
That way you are sure that there was a problem when you start the program and the lock-file is still there.
In pseudo code (I'm not very fluent in AHK):
- check if file exists. If yes: alert and stop; if not: proceed
- create file
- (do your magic here)
- remove file
- check if file is removed. If not:alert; if yes: add entry to your logfile and exit
(Doesn't have to be a file, of course. Something like a reg-key would do to.)
That way you are sure that there was a problem when you start the program and the lock-file is still there.
In pseudo code (I'm not very fluent in AHK):
- check if file exists. If yes: alert and stop; if not: proceed
- create file
- (do your magic here)
- remove file
- check if file is removed. If not:alert; if yes: add entry to your logfile and exit
(Doesn't have to be a file, of course. Something like a reg-key would do to.)
Who is online
Users browsing this forum: skeerrt and 132 guests