Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_FileCountLinesEx

beta _FileCountLinesEx

  • Please log in to reply
4 replies to this topic

#1 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,159 posts

Posted 20 May 2012 - 02:26 PM

This is just to demonstrate the latest feature of V3.3.9.4+ Beta (V3.3.9.3 had a problem so it's not recommended to use this.)
ConsoleWrite('Number of lines: ' & _FileCountLinesEx(@ScriptFullPath) & @CRLF) ; Works only with V3.3.9.4 and above. This is a different approach to _FileCountLines using the new feature StringSplit('Text, Text', ',')[1]. Func _FileCountLinesEx($sFilePath)     Local $sData = StringStripWS(FileRead($sFilePath), 2)     If StringInStr($sData, @LF) Then         Return StringSplit(StringStripCR($sData), @LF)[0]     ElseIf StringInStr($sData, @CR) Then         Return StringSplit($sData, @CR)[0]     Else         If StringLen($sFilePath) Then             Return 1         Else             Return SetError(1, 0, 0)         EndIf     EndIf EndFunc   ;==>_FileCountLinesEx

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 30/07/2014








#2 stormbreaker

stormbreaker

    More wits this time...

  • Active Members
  • PipPipPipPipPipPip
  • 547 posts

Posted 20 May 2012 - 04:34 PM

guinness, does it work for larger files (100+ MB, I suppose). I made something like this by modifying Zinthose's functions (and it took 38 seconds on my pc on a 140 MB file):

AutoIt         
#include <WinAPI.au3> $COUNT = 0 $start = default While 1 $res = _HexSearch("G:\WIN7\sources\boot.wim", StringToBinary("" & @crlf), $start) $start = $res + 2 $COUNT = $COUNT + 1 If $res = -1 then exitloop Wend msgbox(64, "", "Lines count: " & $COUNT) Func _HexSearch($FilePath, $BinaryValue, $StartOffset = Default)           Local $Buffer, $ptr, $hFile, $Result, $Read, $SearchValue, $Pos, $BufferSize = 2048             If $StartOffset = Default      Then $StartOffset = 0             If Not FileExists($FilePath)    Then    Return SetError(1, @error, 0)             $fLen = FileGetSize($FilePath)             If $StartOffset > $fLen      Then   Return SetError(2, @error, 0)             If Not IsBinary($BinaryValue)   Then    Return SetError(3, @error, 0)             If Not IsNumber($StartOffset)   Then    Return SetError(4, @error, 0)             $SearchValue = BinaryToString($BinaryValue)             $Buffer = DllStructCreate("byte[" & $BufferSize & "]")             $ptr = DllStructGetPtr($Buffer)                 $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 1)                 If $hFile = 0 Then Return SetError(5, @error, 0)             $Result = _WinAPI_SetFilePointer($hFile, $StartOffset)             $err = @error             If $Result = 0xFFFFFFFF Then                 _WinAPI_CloseHandle($hFile)                 Return SetError(5, $err, 0)             EndIf             $Pos = $StartOffset             While True                     $Read = 0                     $Result = _WinAPI_ReadFile($hFile, $ptr, $BufferSize, $Read)                     $err = @error                     If Not $Result Then                         _WinAPI_CloseHandle($hFile)                         Return SetError(6, $err, 0)                     EndIf                     $Result = DllStructGetData($Buffer, 1)                     $Result = BinaryToString($Result)                     $Result = StringInStr($Result, $SearchValue)                     If $Result > 0 Then ExitLoop                     If $Read < $BufferSize Then                         _WinAPI_CloseHandle($hFile)                         Return -1                     EndIf                     $Pos += $Read                               WEnd             _WinAPI_CloseHandle($hFile)             If Not $Result Then Return SetError(7, @error, 0)             $Result = $Pos + $Result - 1             Return $Result     EndFunc


And yes, the latest beta does have improvements... thank you!!! ;)

Edited by MKISH, 20 May 2012 - 04:35 PM.

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1


#3 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,159 posts

Posted 20 May 2012 - 04:50 PM

Great, but my point was just to showcase the latest addition. I wanted to add this to the snippets section but it was discussed with that only code that works with stable version should be added. I think the function should be used on source/text files really.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 30/07/2014


#4 stormbreaker

stormbreaker

    More wits this time...

  • Active Members
  • PipPipPipPipPipPip
  • 547 posts

Posted 20 May 2012 - 04:55 PM

Thanks for your quick reply, friend. And yes, the example is OK. I just found another method so I figured I'll tell everyone about it.

Good day/Good night to all... I shall go to sleep now...

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1


#5 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,159 posts

Posted 20 May 2012 - 05:00 PM

Why not post it to the snippets section?

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 30/07/2014





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users