| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 8:12 am Post subject: [SOLVED]Empying A Binary File To Zero-Byte size. |
|
|
Solved, thanks to nog_lorp (and Dark Byte for his tips too).
Last edited by DeletedUser14087 on Fri Oct 31, 2008 2:55 am; edited 2 times in total |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 26002 Location: The netherlands
|
Posted: Thu Oct 30, 2008 8:50 am Post subject: |
|
|
delete it and create a new file with the same name at that location without writing to it
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 8:54 am Post subject: |
|
|
| Dark Byte wrote: | | delete it and create a new file with the same name at that location without writing to it |
that's the exact thing assaf84 told me, and i told him "i'm looking for a challenge, every baby can do that".
Isn't there a way to flush the file's buffer and re-write to it ?.
Edit:
CreateFile (OPEN_EXISTING) -> FlushFileBuffer(wtf) -> WriteFile -> CloseHandle.
|
|
| Back to top |
|
 |
sphere90 Grandmaster Cheater
Reputation: 0
Joined: 24 Jun 2006 Posts: 912
|
Posted: Thu Oct 30, 2008 9:19 am Post subject: |
|
|
| Rot1 wrote: | | CreateFile (OPEN_EXISTING) -> FlushFileBuffer(wtf) -> WriteFile -> CloseHandle. |
Seriously dude, check what a function does before using it. Do you know what FlushFileBuffers actually do? It "flushes the buffers of a specified file and causes all buffered data to be written to a file". It doesn't clear a file. Flushing a FILE and flushing the FILE BUFFER are totally different things.
Last edited by sphere90 on Thu Oct 30, 2008 9:23 am; edited 1 time in total |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 9:23 am Post subject: |
|
|
| sphere90 wrote: | | Rot1 wrote: | | CreateFile (OPEN_EXISTING) -> FlushFileBuffer(wtf) -> WriteFile -> CloseHandle. |
Seriously dude, check what a function does before using it. Do you know what FlushFileBuffers actually do? It "flushes the buffers of a specified file and causes all buffered data to be written to a file". Flushing a FILE and flushing the FILE BUFFER are totally different things. |
It's alike CopyFile() i assume ? could be a 2nd use for WriteFile() too.
|
|
| Back to top |
|
 |
sphere90 Grandmaster Cheater
Reputation: 0
Joined: 24 Jun 2006 Posts: 912
|
Posted: Thu Oct 30, 2008 9:27 am Post subject: |
|
|
| Rot1 wrote: | | sphere90 wrote: | | Rot1 wrote: | | CreateFile (OPEN_EXISTING) -> FlushFileBuffer(wtf) -> WriteFile -> CloseHandle. |
Seriously dude, check what a function does before using it. Do you know what FlushFileBuffers actually do? It "flushes the buffers of a specified file and causes all buffered data to be written to a file". Flushing a FILE and flushing the FILE BUFFER are totally different things. |
It's alike CopyFile() i assume ? could be a 2nd use for WriteFile() too. |
Sometimes file operations are not synchronous. The bytes that you write to a file using WriteFile is written to a temporary buffer first. When you call FlushFileBuffers, the bytes that are stored in the buffer will be written to your file.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 9:33 am Post subject: |
|
|
| ok sphere90, i understand but lets not go off-topic, if there isn't a way to make a file empty then i guess i'll have to delete it.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Oct 30, 2008 10:51 am Post subject: |
|
|
| Code: | FILE *f;
f = fopen("file.bin", "w");
fclose(f); |
|
|
| Back to top |
|
 |
SXGuy I post too much
Reputation: 0
Joined: 19 Sep 2006 Posts: 3551
|
Posted: Thu Oct 30, 2008 11:30 am Post subject: |
|
|
| Jani wrote: | | Code: | FILE *f;
f = fopen("file.bin", "w");
fclose(f); |
|
Doesnt that just open a file with write permissions and then closes it? how does that help?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 26002 Location: The netherlands
|
Posted: Thu Oct 30, 2008 12:26 pm Post subject: |
|
|
no, that's w+
w is create/replace file with 0 size with write access
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Oct 30, 2008 1:27 pm Post subject: |
|
|
| Rot1 wrote: | | that's the exact thing assaf84 told me, and i told him "i'm looking for a challenge, every baby can do that". |
The point of program is not to make it fancy, but to make it efficient .
If the easiest and most efficient way is to just delete the file and recreate it, then use that instead of thinking of some dumb retarded way that you don't know how to do.
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 2:25 pm Post subject: |
|
|
| lurc wrote: | | Rot1 wrote: | | that's the exact thing assaf84 told me, and i told him "i'm looking for a challenge, every baby can do that". |
The point of program is not to make it fancy, but to make it efficient .
If the easiest and most efficient way is to just delete the file and recreate it, then use that instead of thinking of some dumb retarded way that you don't know how to do. |
well, that's why i'm asking, and if you don't know how to do it then don't reply !.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Oct 30, 2008 2:31 pm Post subject: |
|
|
He already told you how to do it. Stop being stubborn and trying to make shit complicated.
Lesson learned: Not everything has to be complicated to be the correct and efficient way!
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Oct 30, 2008 2:39 pm Post subject: |
|
|
| blankrider wrote: | He already told you how to do it. Stop being stubborn and trying to make shit complicated.
Lesson learned: Not everything has to be complicated to be the correct and efficient way! |
I'm not!, i'm asking for a method OTHER THAN deleting a file, then he comes saying "stop trying doing stuff you don't know", how does it help me ? jesus am i the only one who get fucking pissed @ fucktards.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Oct 30, 2008 3:00 pm Post subject: |
|
|
| Rot1 wrote: | | blankrider wrote: | He already told you how to do it. Stop being stubborn and trying to make shit complicated.
Lesson learned: Not everything has to be complicated to be the correct and efficient way! |
I'm not!, i'm asking for a method OTHER THAN deleting a file, then he comes saying "stop trying doing stuff you don't know", how does it help me ? jesus am i the only one who get fucking pissed @ fucktards. |
Why are you looking for a method other than this one? It's the most simplistic.
|
|
| Back to top |
|
 |
|