darkmaster071 Posted July 31, 2010 Share Posted July 31, 2010 (edited) Hi, im wondering if there is a function or any way to delete text content of a text file (.log file) without deleting the actual file. I have been searching through the help file and the forums but ive come across nothing usefull. Help much appreciated. Thanks. Edited July 31, 2010 by darkmaster071 Link to comment Share on other sites More sharing options...
smashly Posted July 31, 2010 Share Posted July 31, 2010 Hi,$hFO = FileOpen("test.log", 2) FileWrite($hFO, "") FileClose($hFO) Cheers atetester132 1 Link to comment Share on other sites More sharing options...
ProgAndy Posted July 31, 2010 Share Posted July 31, 2010 Just open the file in overwrite mode and close it without writing anything to it $hFile = FileOpen($sFile, 2) FileClose($hFile) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
darkmaster071 Posted July 31, 2010 Author Share Posted July 31, 2010 Thanks, didnt think of that. Link to comment Share on other sites More sharing options...
MvGulik Posted July 31, 2010 Share Posted July 31, 2010 (edited) Just tinkering around a bit. test() If @error Then Exit @error Func test() Local $sFilespec = @ScriptDir & '\' & 'TestFile.tmp' If FileExists($sFilespec) And Not FileDelete($sFilespec) Then Return SetError(1) If Not FileWrite($sFilespec, 'abcdef') Then Return SetError(2) If Not _ZeroWipe_FileContent($sFilespec) Then Return SetError(@error) If Not _Zero_FileSize($sFilespec) Then Return SetError(@error) EndFunc ;; http://www.autoitscript.com/forum/index.php?showtopic=117880&view=findpost&p=820821 Func _ZeroWipe_FileContent($sFilespec) Local $iFileSize = FileGetSize($sFilespec) If @error Or Not $iFileSize Then Return SetError(11, 0, 0) Local $hFile = FileOpen($sFilespec, 2 + 16) If $hFile = -1 Or $hFile < 1 Then Return SetError(12, 0, 0) If Not FileSetPos($hFile, $iFileSize - 1, 0) Then Return SetError(13, 0, 0) If Not FileWrite($hFile, Binary(Chr(0))) Then Return SetError(14, 0, 0) If Not FileClose($hFile) Then Return SetError(15, 0, 0) Return 1 ;~ If Not FileSetPos($hFile, (Ceiling(($iFileSize) / 512) * 512)-1, 0) Then Return SetError(3,0,0) ;; MFT note: This is only good for files that are not stored in MFT system file. EndFunc Func _Zero_FileSize($sFilespec) Local $hFile = FileOpen($sFilespec, 2) If $hFile = -1 Or $hFile < 1 Then Return SetError(22, 0, 0) If Not FileClose($hFile) Then Return SetError(25, 0, 0) Return 1 EndFunc + MFT note. Edited July 31, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
ProgAndy Posted July 31, 2010 Share Posted July 31, 2010 (edited) _ZeroWipe_FileContent wont work i think. Edit: OK. Did not understand it Edited July 31, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
MvGulik Posted July 31, 2010 Share Posted July 31, 2010 (edited) Why do you think that ? Last time I checked (before posting) it was working fine. ... yep, still working correct on this side. Edited July 31, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
ProgAndy Posted July 31, 2010 Share Posted July 31, 2010 OK it works, but why would you need that? *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
MvGulik Posted July 31, 2010 Share Posted July 31, 2010 (edited) Don't know. Edited August 3, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now