bluerein Posted November 18, 2008 Share Posted November 18, 2008 I have around 4000 txt files in a directory with subdirectorys .. I need to remove the last line of each file and replace with a new line.... Whats the best way to go about it?? Thanks Link to comment Share on other sites More sharing options...
Airwolf Posted November 18, 2008 Share Posted November 18, 2008 (edited) I have around 4000 txt files in a directory with subdirectorys .. I need to remove the last line of each file and replace with a new line....Whats the best way to go about it??Thanks_FileListToArray, and then run through the array with a For...Next loop. For each file in the loop, you'd have to count the lines in the file and then do a _FileWriteToLine to delete the last line. In summation, read the help file topics for _FileListToArray, For...Next, _FileCountLines and _FileWriteToLine. Edited November 18, 2008 by Airwolf Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
bluerein Posted November 18, 2008 Author Share Posted November 18, 2008 Thanks got it!! Link to comment Share on other sites More sharing options...
zorphnog Posted November 18, 2008 Share Posted November 18, 2008 (edited) Or use FileFindFirstFile/FileFindNextFile to step through the directory structure recursively. $sPath = "C:\my\Txt\Directory" RecurseDirs($sPath, "txt") Func RecurseDirs ($sPath, $sExt, $sSpacer = " ") Local $hSearch, $sFile, $sFilePath $hSearch = FileFindFirstFile($sPath & "\*") If $hSearch = -1 Then Return While 1 $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop $sFilePath = $sPath & "\" & $sFile If StringInStr(FileGetAttrib($sFilePath), "D") <> 0 Then ConsoleWrite($sSpacer & $sFilePath & @LF) RecurseDirs($sFilePath, $sExt, $sSpacer & " ") Else If StringRegExp($sFile, "(?i)\." & $sExt & "\z", 0) Then ; Add File Read/Write processing here ConsoleWrite($sSpacer & $sFilePath & @LF) EndIf EndIf WEnd EndFunc Edited November 18, 2008 by zorphnog Link to comment Share on other sites More sharing options...
youknowwho4eva Posted November 18, 2008 Share Posted November 18, 2008 I may be mistaken but I believe if you tell _filewritetoline to write to line -1 it automatically writes to the last line in the file. Giggity 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