Juno_okyo

_FileDeleteLine (UDF)

Feb 22nd, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.12 KB | None | 0 0
  1. #include-once
  2. #include <Array.au3>
  3.  
  4. ; #FUNCTION# ====================================================================================================================
  5. ; Name...........: _FileDeleteLine
  6. ; Description ...: Delete a line in the file
  7. ; Syntax.........: _FileDeleteLine($sFilePath, $lineNumber)
  8. ; Parameters ....: $sFilePath   - File name or file path
  9. ;                  $lineNumber  - Line number in the file that you want to delete
  10. ; Return values .: Success      - True
  11. ;                  Failure      - Flase
  12. ; Author ........: Juno_okyo <junookyo@gmail.com>
  13. ; ===============================================================================================================================
  14. Func _FileDeleteLine($sFilePath, $lineNumber)
  15.     If Not FileExists($sFilePath) Or Not IsNumber($lineNumber) Then Return False
  16.  
  17.     ;=> Remove line using array
  18.     Local $aFile = FileReadToArray($sFilePath)
  19.     _ArrayDelete($aFile, $lineNumber - 1)
  20.     If @error Then Return False
  21.  
  22.     ;=> Rewrite
  23.     Local $fp = FileOpen($sFilePath, 2 + 256)
  24.     For $line In $aFile
  25.         FileWriteLine($fp, $line)
  26.     Next
  27.     FileClose($fp)
  28.  
  29.     Return True
  30. EndFunc
Add Comment
Please, Sign In to add comment