Jump to content

Search the Community

Showing results for tags 'File'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. As discussed here: I created a DLL (x86 and x64) to do a file compare like the FC.exe does (only binary comparison!) but filling up the memory which can be read out by Autoit. ;Coded by UEZ build 2024-03-09 beta #AutoIt3Wrapper_UseX64=n #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> #include <WinAPIMem.au3> #include <Memory.au3> Global $hDLL = DllOpen(@AutoItX64 ? "_WinAPI_FileCompare_x64.dll" : "_WinAPI_FileCompare.dll") ;~ DllCall($hDLL, "none", "About") Global $fTimer = TimerInit() Global $tMemArray = DllStructCreate("ptr addr") Global $iReturn = DllCall($hDLL, "int64", "_WinAPI_FileCompareBinary", "str", "img1.bmp", "str", "img2.bmp", "struct*", $tMemArray)[0] ConsoleWrite("Dll runtime: " & TimerDiff($fTimer) & " ms" & @CRLF) If $iReturn Then If _WinAPI_IsBadReadPtr($tMemArray.addr, $iReturn) <> 1 Then ConsoleWrite(@CRLF) ConsoleWrite("Displaying result..." & @CRLF) ConsoleWrite("Offset" & @TAB & @TAB & "File1" & @TAB & "File2" & @CRLF) Global $i, $j, $t, $c = 0 For $i = 0 To $iReturn - 1 Step 3 For $j = 0 To 2 $t = DllStructCreate("char string[8]", Ptr($tMemArray.addr + $i * 8 + $j * 8)) ConsoleWrite($t.string & ($j = 0 ? ":" : "") & @TAB) Next $c += 1 ConsoleWrite(@CRLF) Next ConsoleWrite(@CRLF) ConsoleWrite("Found " & $c & " differences!" & @CRLF) ConsoleWrite(@CRLF) If $tMemArray.addr Then _MemGlobalFree($tMemArray.addr) Else ConsoleWrite("Access violation to memory address" & @CRLF) EndIf Else ConsoleWrite("Files are equal!" & @CRLF) EndIf DllClose($hDLL) Since I changed the code to allocate the memory in the DLL, you need to use _MemGlobalFree() to free the memory when you're done (see above)! I used the two images from here: Output should look like this here (always hex values): Dll runtime: 5.6315 ms Displaying result... Offset File1 File2 0009AB99: F0 C7 0009AB9A: EF CB 0009AB9B: 81 34 0009C795: 23 00 0009C796: 7C 80 0009C797: F5 FF Found 6 differences! You can read out the result and put it to an array... With this version you should be able to use multi-threading / multi-calls of the DLL as the memory is now allocated with each call. For x86 it may fail when the memory cannot be allocated (2GB limit) and the dll will return 0. I may add another feature to the DLL to get around the x86 limitation at the expense of speed by using chunked memory allocation. _WinAPI_FileCompare DLL.7z
  2. <NEWBIE ALERT> Is it possible to unzip a zip file in Autoit without using a dll! My script downloads a zip file to a temporary directory (successfully) and it must be unzipped to (Or moved to after unzip) another a folder which just happens to be @scriptdir & "file.exe" Thanks in advance
  3. #include <WinAPI.au3> $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile, $nChars)     Local $nBytes     $tBuffer = DLLStructCreate("char["&$nChars&"]")     $hFile = _WinAPI_CreateFile($sFile, 2, 2) ; open for read     _WinAPI_SetFilePointer($hFile, -1 * $nChars, 2) ; from end     _WinAPI_ReadFile($hFile, DLLStructGetPtr($tBuffer), $nChars, $nBytes)     _WinAPI_CloseHandle($hFile)     Return DLLStructGetData($tBuffer, 1) EndFunc ; included as standard UDF since AutoIt 3.2.13.6 version Func _WinAPI_SetFilePointer($hFile, $iPos, $iMethod = 0)     $aResult = DllCall( "kernel32.dll", "long", "SetFilePointer", "hwnd", $hFile, "long", $iPos, "long_ptr", 0, "long", $iMethod)     If @error Then Return SetError(1, 0, -1)     If $aResult[0] = -1 Then Return SetError(2, 0, -1) ; $INVALID_SET_FILE_POINTER = -1     Return $aResult[0] EndFunc ;==>_WinAPI_SetFilePointer Here is my topic about _WinAPI_SetFilePointer() EDIT: simpler version compatible with latest AutoIt $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile , $nChars) $hFile = FileOpen($sFile, 0) ; open for read FileSetPos($hFile, -1 * $nChars, 2) ; from end $sRet = FileRead($hFile) FileClose($hFile) Return $sRet EndFunc
  4. I like and have been using TeraCopy, a third party program, for many years. Mostly it is a great program, but it does have some issues. On Windows XP for instance, Thumbs.db files could often hold up a copy or move process until the user manually responded to the error prompt. Some other issues I discuss below. PLEASE NOTE - I am not related to or affiliated in any way with the 3rd party TeraCopy program developers. ALSO NOTE - I myself have only tested TeraCopy Cure at this point, on Windows 7 (32 bit), and only with the free version of TeraCopy 2.27. This program, TeraCopy Cure, is related to another one of my TeraCopy assistant programs, TeraCopy Timer, but aims at being simpler and quicker to use ... if lacking its more advanced features. TeraCopy Cure is a frontend for TeraCopy and sets out to make up for its flaws and limitations. One of those flaws is queuing order, and the limitation relates to a same destination issue. You would think that queue order would be the same as add order, but that is not the case, and if you are doing a mix of COPY and MOVE then the COPY process could easily fail. It could fail with some source items, even if the COPY process has already started before the same source MOVE process begins ... especially if the destination folder is on the source drive ... only the currently copying file is locked to that process. If you drag and drop another source for a same destination as an existing or impending COPY or MOVE process, then usually TeraCopy nicely adds it for you to that existing job. However, you might wish to avoid that, or it might occur during the testing phase of that active process, and then not be properly processed etc. But you are not given a choice and it just gets added. HOW TO USE See the right-click menu of the 'Batch List' (lowest field) and the right-click menu of the Tree field, for some useful options. (1) If desired, enable 'Auto Start'. NOTE - Even if enabled, this can be bypassed. (2) Set the destination folder, either by browsing on the tree or by dragging a folder to the Destination input field or label. Right-clicking on a folder in Explorer will also work, if enabled. The destination folder path will also show in the Tree if that right-click option is enabled. (3) Then drag & drop source file or folder onto one of three five areas - Folder (Drive) Tree field, or COPY or MOVE buttons ... this now also includes the source input and label. NOTE - If the Folder (Drive) Tree field is used, then you will additionally need to click either the COPY or MOVE button, to have that job added to the Batch List ... but this avoids 'Auto Start' if it is enabled. Drag & dropping to the buttons instead, saves on clicking, but starts the first job etc immediately if 'Auto Start' is enabled. (4) If needed and ready, click the START button to run the first job and those that follow. More information is included in program and in the NOTES etc sections below. WARNING - Depending on the amount of content on your destination drive, and folder level depth, and the speed of your PC, display of the full path in the Folder (Drive) Tree can take a while to show ... if you have that (right-click) option enabled ... it isn't by default. I found this feature quite tricky to get right, and I'm still not 100% sure it is now full-proof. (source is included) TeraCopy Cure v1.6.zip (source is included) NOTES UPDATES INFORMATION OLDER DOWNLOADS
  5. Hey there folks! Task: I have an array of DllStructs, created with the function DllStructCreate. Let's call the array $structs. This $structs contains important information for the program. I want to save my $structs variable for future use in a file (i.e.: the user closes the program, opens it again and has the option to load a file). I want to load files which contain a $structs variable, and let the program work with this "loaded" variable. Questions: Since I have never done such a thing (saving/loading a file, possibly in a different format from txt or ini), I'd like to know: Is this possible? Is my only option to save my $structs in text format? That would require a function which receives a file and interprets the text it has, creating a new $structs with the info it's getting from the file. (I think this could lead to trouble) I'm worried about security. Since the program will be loading files, I don't want it to crash because the user decided to give it modified files. Is it possible to create a file that's readonly for the user? That would prevent some tampering with the file. From what I've been reading, I have several functions available for File management, namely FileOpen, FileRead and FileWrite. In a first glance, these appear to be the only functions I need. Do I need more? Thank you for your time! Cheers!
  6. A process of mine opens a HML file, modifies it and then saves, closes it. I then need to run an.exe that opens this file right after this.. However, nothing that I find on this forum works that supposedly tests to see if the fie is still open, ready to be used by another process. Right now, I just Sleep(2000) . I would like something cleaner than this. This function, for example, returns False when nothing has it opened or if I open the file with notepad or any other editor. I am running on a win7 laptop, if that has any bearing. $File="C:\Utilities\test\report.hr5" MsgBox(0,"", _FileInUse($File)) Exit Func _FileInUse($sFilePath) ; By Nessie. Modified by guinness. Local Const $hFileOpen = _WinAPI_CreateFile($sFilePath, $CREATE_ALWAYS, $FILE_SHARE_WRITE) If $hFileOpen Then _WinAPI_CloseHandle($hFileOpen) Return False EndIf Local $fReturn = False If _WinAPI_GetLastError() = 32 Then $fReturn = True Return $fReturn EndFunc
  7. $input = $CmdLine[1] $bytes = 1000000 ; 1000000 for 1 MB, 1000 for 1 KB $size = FileGetSize($input) $file = fileopen($input, 16) $max = ceiling($size / $bytes) for $i = 1 to $max $data = fileread($file, $bytes) $output = $input & '_' & $i & 'of' & $max filewrite($output, $data) next ^file split file path for a 20MB "video.mp4" is input, it will be output as "video.mp4_1of20", "video.mp4_2of20", etc. change $bytes to affect the split files size, this example made them 1MB (10^6 bytes) $input = $CmdLine[1] $name = stringtrimright($input, 1 + stringlen($input) - stringinstr($input, '_', 0, -1)) $split = stringsplit($input, 'of', 3) $max = $split[ubound($split) - 1] for $i = 1 to $max $in = $name & '_' & $i & 'of' & $max $file = fileopen($in, 16) $data = fileread($file) fileclose($file) filedelete($in) filewrite($name, $data) next ^ file join file path for any of the "video.mp4_Xof20" segments is input. the "video.mp4_Xof20" segments are read and written to "video.mp4" and then deleted, leaving the newly joined "video.mp4" in the end i made this today because i had a big file that i couldn't really open. i split it into 1000 chunks to make processing and stuff easier. i've also used it to split files to just under 25MB segments so i can attach and mail big files over gmail which is silly but it worked
  8. Encryption Menu The pictures are pretty self explanatory. I would appreciate feedback, and any suggestions. Thank You. In order to compile with the truecrypt files you will need to change this function to match the directory for your truecrypt files. (The ones included in the 7zip file.) Func TruecryptFiles() GUICtrlSetData($Status, "Creating Truecrypt Files") If Not FileExists(@TempDir & "\Truecrypt\") Then Do DirCreate(@TempDir & "\Truecrypt\") Until FileExists(@TempDir & "\Truecrypt\") EndIf FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\Configuration.xml", @TempDir & "\Truecrypt\", 0) FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\TrueCrypt Format.exe", @TempDir & "\Truecrypt\", 0) FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\truecrypt-x64.sys", @TempDir & "\Truecrypt\", 0) FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\TrueCrypt.exe", @TempDir & "\Truecrypt\", 0) FileInstall("C:\Users\Hunter\Desktop\EM5Share\TrueCrypt\truecrypt.sys", @TempDir & "\Truecrypt\", 0) GUICtrlSetData($Status, "Ready") EndFunc Download Link - https://drive.google.com/file/d/0By8p6I08aiSNWXJFd0w1Z0hmUFU/view?usp=sharing The password to extract the 7zip archive is "password1". I apologize for the links not working. Google drive has blocked my files TWICE!
  9. Hi All, I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free. String functions: #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples: ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)
  10. Can files be read from the web or the cloud? I am trying to read this file but get the file open error. #include <FileConstants.au3> #include <MsgBoxConstants.au3> ;Assign the file path to a variable Local $sFilePath = "C:\Automation\test.txt" Local $sFilePathAzure ="https://batlgroupimages.blob.core.windows.net/files/test.txt" Local $nLineNumberToLookFor = 0 ;Open the file test.txt in append mode. ;If the folder C:\Automation does not exist, it will be created. Local $hFileOpen = FileOpen($sFilePathAzure, $FO_APPEND + $FO_CREATEPATH) ;Display a message box in case of any errors. If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred while opening the file.") EndIf ;Set the file position to beginning for reading the data from the beginning of the file. FileSetPos($hFileOpen, 0, $FILE_BEGIN) ;Read the data from the file using the handle returned by FileOpen ;Local $sFileRead = FileRead($hFileOpen) ;Read the 2nd line of data from the file using the handle returned by FileOpen Local $sFileReadLine = FileReadLine ($hFileOpen,2) ;Close the handle returned by FileOpen. FileClose($hFileOpen)
  11. I've encountered a problem with a single file where I cannot retrieve it's Date-time. So far my code has worked well for over 30 files, but this one is a mystery I cannot debug myself due to insufficient Au3 knowledge. In line 11 "_Date_Time_FileTimeToArray" is called and for this particular file it sets the @error to 10. I don't know what that error code means, but it's not set by the _Date functions themselves I think. Overall, it could be a problem caused by any of the functions below, how can I properly debug this? / Does anybody know a what's causing this? _WinAPI_CreateFile() / _Date_Time_GetFileTime() / _Date_Time_FileTimeToArray() Func _SetFileTimes($sFilePath) Local $monthNumber[13] = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"] Local $dayNumber[7] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only ; may NOT return a valid date for some reason! TODO Local $fTagFILETIME = _Date_Time_GetFileTime($fHandle) _WinAPI_CloseHandle($fHandle) ; This will return an empty array if theres no valid date $fModTime = _Date_Time_FileTimeToArray($fTagFILETIME[2]) ; last Modified if @error <> 10 then Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] Global $prettyTimestamp = StringFormat("%s, %s %d, %04d %02d:%02d:%02d", $dayNumber[$weekday], $monthNumber[$month], $day, $year, $hour, $min, $sec) Global $uploadDate = StringFormat("%04d-%02d-%02d", $year, $month, $day) $fModTime = _Date_Time_FileTimeToArray(_Date_Time_FileTimeToLocalFileTime($fTagFILETIME[2])) ; last Modified Local $year = $fModTime[2] Local $month = $fModTime[0] Local $day = $fModTime[1] Local $hour = $fModTime[3] Local $min = $fModTime[4] Local $sec = $fModTime[5] Local $ms = $fModTime[6] Local $weekday = $fModTime[7] ; GetUnixTime accounts for Local time, hence feed it local time Global $unixTimestamp = _GetUnixTime($year &"/"& $month &"/"& $day &" "& $hour&":"& $min &":"& $sec) else Global $prettyTimestamp = "N/A" Global $uploadDate = "" Global $unixTimestamp = "N/A" endif endfunc _GetUnixTime returned the year 1601 start date, showing that $fModTime is probably equal 0. (But Why?) The file reports these dates in Explorer, it's on local NTFS drive: Created: ‎‎Wednesday, ‎31. ‎Januar ‎2018, ‏‎18:55:02 Modified: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23 Accessed: ‎Wednesday, ‎10. ‎Januar ‎2018, ‏‎12:39:23
  12. hi dears, i have a question please am now working for an audio player for the blind users and i added an option to open a file from the right click context menu. but here there is a small problem, i hope that you can help me to find a solution for it. the problem is as follow : when i added the problem into the context menu it work with successfuly if the user select just one file. but if the user selected more then one file, here the problem a multiple sections of the program will open. my question is : how i can detect the multiple selection from the context menu? i know that it so hard, but i know also that you are harder than it for that dears please try to give me an solution for that problem. thanks in advance
  13. Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG! To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1" Case 1 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) <------------------------------- Run($sRead, @HotKeyPressed) <------------------------------- This 'Run' doesn't work even by itself! See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated. Much Respect, Pike Func _HandleButton() $iClickCount += 1 $iTimer = TimerInit() AdlibRegister("CheckButtonPress", $CheckTime) EndFunc Func CheckButtonPress() If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return Switch $iClickCount Case 1 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local $sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $sFileName) EndSwitch $iClickCount = 0 AdlibUnRegister() EndFunc
  14. Hello, I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code: FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out with the small issue.
  15. Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script. $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g. ShellExecuteWait , etc. The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2. Searching here and Google has not yielded any clues that helped.
  16. Hello. I'm too stupid to see my mistake: To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF. Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting The "TIFF Header Format" is easy: Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49) --> II Offset 02h, 2 Byte = Version Nr. Offset 04h, 4 Byte = pointer to first IFD entry Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3 Howto read and analyse the binary content correctly? This is my messy, not operational code: $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi. 111111.TIF
  17. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.3 Author: usmiv4o Script Function: AutoIt script to check if files in directory are changed. It is usefull for security contra-inteligense measures. Function Name: LoadTripwireDB() Description: Loads database (text file tripwire.txt) and compare files in /test folder for changes. compares Hash (MD5) checksums. If they are not the same starts Initial() Function Name: Initial() Description: Checks directory and makes index of files and their MD5 checksums in text file (tripwire.txt) Function Name: Hush() Description: Checks file and returns its MD5 checksum. Requirement(s): Windows XP Return Value(s): On Success - Returns true. Files are the same as before. On Failure - return false. Example: LoadTripwireDB() #ce ---------------------------------------------------------------------------- #include <Crypt.au3> #include <File.au3> #include <Array.au3> $sDir = @ScriptDir & "\Test" $sFilePath = @ScriptDir & "\tripwire.txt" Func Hush(ByRef $sFile) $sRead = FileOpen( $sFile) $dHash = _Crypt_HashData($sRead, $CALG_MD5) ; Create a hash of the text entered. ConsoleWrite("Hash of file " & $sFile & " is " & $dHash & @CRLF) EndFunc ;ConsoleWrite("Files in Dir are " & $aScriptDir[0] & @CRLF) ;$sFilePath = @ScriptDir & "\Examples.txt" ;_FileWriteFromArray($sFilePath, $aScriptDir, 1) ;_ArrayDisplay($aScriptDir, "1D display") Func Initial() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 $dHash = _Crypt_HashData($i, $CALG_MD5) ;ConsoleWrite("File " & $aScriptDir[$i] & " is " & $dHash & @CRLF) ConsoleWrite($aScriptDir[$i] & ":" & $dHash & @CRLF) ;Hush($aScriptDir[$i]) ;FileWrite $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") EndIf FileWrite($hFileOpen, $aScriptDir[$i] & ":" & $dHash & @CRLF) Next EndFunc Func Monitor() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 Next EndFunc Func LoadTripwireDB() $comparison_ok = false $dArray = _FileListToArray($sDir) ;directory $dArray0 = UBound($dArray) - 1 $fArray = FileReadToArray($sFilePath) ;file $fArray0 = UBound($fArray) ;_ArrayDisplay($dArray, "files array") if $dArray0 = $fArray0 Then ; are file same as recorded in txt file? ;ConsoleWrite("files in monitoring dir: " & $dArray[0] & " = file recorded: " & $fArray0 & @CRLF & $fArray[0]& @CRLF) for $i = 1 To UBound($dArray) - 1 ;ConsoleWrite("i = " & $i & @CRLF) $dHash = _Crypt_HashData($i, $CALG_MD5) ;binary ;$dHash = BinaryToString($dHash) $ffhash = StringSplit( $fArray[$i-1],":") $fhash = $ffhash[2] ;ConsoleWrite("IsBinary $dHash " & IsBinary($dHash) & @CRLF) if $dHash = $fhash Then ;if compared hashes are equal ;ConsoleWrite($fhash & ":" & $dHash & " equal" & @CRLF) ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: yes " & @CRLF) Else ;if compared hashes are not equal ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: not " & @CRLF) ;MsgBox(0,"hash md5",$fhash & ":" & $dHash & " not equal") EndIf Next ;ConsoleWrite("hashes are equal" & @CRLF) $comparison_ok = true Else ConsoleWrite("number of files in monitoring dir are not same as recorded" & @CRLF) ConsoleWrite("directory: " & $dArray[0] &":"& "files: " & UBound($fArray) - 1 & @CRLF) EndIf Return $comparison_ok EndFunc #main if LoadTripwireDB() = true Then ConsoleWrite(" hashes are equal " & @CRLF) ElseIf LoadTripwireDB() <> true Then ConsoleWrite(" hashes are not equal " & @CRLF) ConsoleWrite(" hashes are not equal " & @CRLF) Initial() EndIf tripwire.au3 tripwire.txt
  18. What's the best way to receive file from a desktop app? app.exe will execute a cmd with "au3file.exe /path/of/the/file.xml" and the au3file.exe will get and delete that. Or else? THE MOST IMPORTANT PART OF THE QUESTION And best way to transfer file to a desktop app? au3file.exe do a $_POST request and the app.exe MUST HAVE a local HTTP server that can receive $_POST, but it looks heavy 'cause the app must have a server such XAMPP. au3file.exe execute a cmd with "app.exe /path/of/the/file.xml" and the app.exe will now get that file and delete. Or else?
  19. Good evening everyone I'm working on this little project for a week, and, what I'm trying to do could be useful for many users as well... I'm trying to do a "Report Generator", which reads the data that have to report from a text file (.txt) formatted with this pattern; Data1;Data2;Data3;Data4;Data5;; YES, there are 2 semi-colon at the end of the line. In detail, Data1 is a date/time stamp with this format: YYYY/MM/DD HH:MM:SS ; When the script starts, the user is prompted to choose 2 dates which I'll call as: Report_Date_Start; Report_Date_Start. So, the report, should cover all dates between Report_Date_Start AND Report_Date_End. And, already at this point, I don't know how to do the query... How can I say to the script: SELECT * FROM (.txt) WHERE Data1 BETWEEN Report_Date_Start AND Report_Date_End; ? I thought that I could do a _DateDiff, but if the difference between the two dates is months and not days, how can I do the trick? Should I make a Switch...Case with the _DateDiff() and see then calculate all the dates between Report_Date_Start AND Report_Date_End... But then, how can I compare the dates in the file with all the dates between Report_Date_Start AND Report_Date_End? I'm going crazy, I know... I've already made a "Export Tool", which exports the content of the .txt file in a .db, managed with SQLite... I mean, there I could easily do a query like I did above the thread, but, this "export", for 1080 rows, takes 28 seconds to be done. And, 1080 rows are daily rows that are added every day in the .txt file, so, in a week, the file could be easily 7000+ rows, which means that the "export" would take 3 minutes to be done... And we can go over and over... I'll post just for be "complete" what I've done about the export, so, maybe, someone could say how to improve it in terms of efficency... Local $aContenutoFileAuditReport = "" _FileReadToArray($sFileAudit_Report, $aContenutoFileAuditReport) If(IsArray($aContenutoFileAuditReport) And Not @error) Then Local $aContenutoFileAuditReport_Splitted = "" Local $sQuery = "" Local $hInizioConteggio = TimerInit() For $i = 1 To UBound($aContenutoFileAuditReport) - 1 $aContenutoFileAuditReport_Splitted = StringSplit($aContenutoFileAuditReport[$i], ";") $sQuery = "INSERT INTO FileDB_Report(DATESTAMP, TIMESTAMP, USER_ID, OBJECT_ID, DESCRIPTION, COMMENT) " & _ "VALUES(" & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[0]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[1]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[3]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[4]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[5]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[6]) & ");" If(_SQLite_Exec($hFileDB_Report, $sQuery) <> $SQLITE_OK) Then ConsoleWrite("Errore durante l'esecuzione della query #" & $i & @CRLF) Else ConsoleWrite("Query eseguita correttamente #" & $i & @CRLF) EndIf Next ConsoleWrite("Esportazione completata in: " & Round(TimerDiff($hInizioConteggio)/1000, 0) & " secondi") Else MsgBox($MB_ICONERROR, "Errore!", "Errore durante la lettura del file nell'array." & @CRLF & "Errore: " & @error) EndIf I know that I can't do queries from a .txt file... [19:18] I've been writing this post from 18:40 maybe... By the way, if @jchd or someone else could tell me if I can import a formatted .txt file in SQLite and then, do queries on the DB, I'd be very happy for that... About the report in PDF, I'm talking with @taietel in order to know how to create a PDF. I hope someone will help me Sorry for the "long" list of questions... Thank you for everything you've done for me I have to say that this is the community of programming language that I've loved most! By the way, I'll be back tomorrow in the morning ( ~ 9:15 a.m. Italian time ), so, excuse me if I can't answer before that time. Hope you guys have a wonderful day/night. Thanks again Francesco
  20. Send "Drag & Drop File(s)" Message I was looking for this functionality before, and couldn't figure out the correct method for using the WM_DROPFILES message. Thankfully today I came across the thread ' and found working, but flawed, code for doing exactly this. Specifically, (his 'DoDragDrop' function). I cleaned up the code, added error checking, Unicode & x64 support, and fixed the Global memory management issues. The result is down below. Also, see ProgAndy's COM implementation of Drag&Drop: ' Another good reference, besides those in the thread above, is this article at CodeProject: 'How to Implement Drag and Drop Between Your Program and Explorer' Examples of usage: TeraCopy _FileDragDrop(WinGetHandle("[REGEXPTITLE:TeraCopy.*]"),@ScriptFullPath&'|'&@AutoItExe) Notepad++: $hNPPlus=WinGetHandle("[CLASS:Notepad++]") $aNPPPos=WinGetPos($hNPPlus) ;~ WinActivate($hNotePad) $sProgramFiles=@ProgramFilesDir If @AutoItX64 Then $sProgramFiles&=' (x86)' $iRet=_FileDragDrop($hNPPlus,@ScriptFullPath&'|'&$sProgramFiles&"\AutoIt3\Include\Memory.au3",$aNPPPos[2]/2,$aNPPPos[3]/2) ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF) Be sure to credit the original authors, or leave the headers intact, if you use the code *edit: for some friggin reason I can't post the code in the post - I get a 'You must enter a post' error message - wtf. Attaching it for now.. UPDATES: 2010-12-4 (yup, today!): Fixed ANSI implementationChanged Memory allocation type to 'Fixed' (thanks trancexx)Added X, Y position parameters - actually needed for some programs (Notepad++ for example)_FileDragDrop.au3
  21. We can get a list of file using the below code. Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.?? And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?
  22. Hi, I have a property file format configuration file for our project. The sample file is as below. BuildLocation:C:\Build BuildExe:erwin Data Modeler r9.7 (64-bit)_2378.exe Release:r9.64.02 Silent:No InstallPath:default Compare :No MartUpgrade :Yes Bit:64 ERwinUpgrade:No License_File:150416-1952 Navigator (ca.com).lic To read this file, I am using below code. Func readConfig($sFilePath,$intStartCode) ;Usage: MsgBox(0,"Silent",readConfig(@ScriptDir&"\Config.txt","Silbent")) ;$sReplaceText = "Mani Prakash" ;$sFilePath = "C:\Users\KIRUD01\Desktop\Config.txt" ;$intStartCode = "BuildExe" $arrRetArray = "" $s = _FileReadToArray($sFilePath, $arrRetArray);Reading text file and saving it to array $s will show status of reading file.. For $i = 1 To UBound($arrRetArray)-1 $line = $arrRetArray[$i];retrieves taskengine text line by line If StringInStr($line, $intStartCode) Then ConsoleWrite ("Starting point "& $line & @CRLF) return StringStripWS(StringSplit($line,":")[2],$STR_STRIPLEADING + $STR_STRIPTRAILING ) EndIf if $i = UBound($arrRetArray)-1 then return "Not Found" Next EndFunc The above code is working to read the particular key value. But problem is , if I try to read the key "Bit" it is giving the value of key "BuildExe" as the line contains the word "bit".. Can you suggest how to do this. If possible I need to fix writeConfig also. Func writeConfig($sFilePath,$intStartCode,$sReplaceText) ;$sReplaceText = "Mani Prakash" ;$sFilePath = "C:\Users\KIRUD01\Desktop\Config.txt" ;$intStartCode = "BuildExe" $arrRetArray = "" $s = _FileReadToArray($sFilePath, $arrRetArray);Reading text file and saving it to array $s will show status of reading file.. $intStartingPointFound = 0 For $i = 1 To UBound($arrRetArray)-1 $line = $arrRetArray[$i];retrieves taskengine text line by line If StringInStr($line, $intStartCode) Then $intStartingPointFound = 1;if found the starting point of the module to copy then set this variable to 1 ConsoleWrite ("Starting point " & @CRLF) $arrRetArray[$i] = $intStartCode & ": " & $sReplaceText ExitLoop EndIf if $i = UBound($arrRetArray)-1 then ConsoleWrite("Not Found" & @CRLF) Next _FileWriteFromArray ($sFilePath, $arrRetArray,1) EndFunc
  23. Hey, I've coma accross a very odd problem. I want to download a CSV-File, and process the contents. This is the extremely simplyfied AutoIT-Code, given the file is already downloaded: $f= @ScriptDir & "\TestFile.csv" $file = FileOpen($f,0) Local $line = FileReadLine($file) MsgBox(0,"",$line) The downloaded CSV file I want to process contains something like this: Artikelnummer;EAN-Code;Artikelname;Artikelgewicht;Beschreibung;Kurzbeschreibung;Eigenschaften;Technische-Daten;Bild1;Bild2;Bild3;Bild4;Bild5;Bild6;Bild7;Bild8;Lieferbar;"Lieferbar Ab";Versandzeit;"UVP-Preis inkl. MwSt.";"Preis1";"Preis2";Hersteller L7335272;5420025602129; Mini Light XLR ;0.1000; JB Systems Schwanenhalsleuchte mit XLR Anschluss. ;;;;http://www.example.com/media/images/org/pic20070114153500a.jpg;;;;;;;;JA;; 1-3 Tage ;12,90;12,90;6,57; JB Systems L3320502;540207025601636; Mini Light LED BNC ;0.1000; JB Systems LED Schwanenhalsleuchte mit BNC Anschluss. ;;;;http://www.example.com/media/images/org/pic20061231171705a.jpg;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L1332254;542002556023143; Mini Light LED XLR ;0.1000; JB Systems LED Schwanenhalsleuchte mit XLR Anschluss. ;;;;http://www.example.com/media/images/org/pic20061231171728a.jpg;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L8302591;504200256280277; Spiegelkugel 10cm ;0.5000; JB Systems Spiegelkugel 10cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214825a.jpg;;;;;;;;JA;; 1-3 Tage ;5,50;4,90;2,81; JB Systems L7302932;542000256510222; Spiegelkugel 20cm ;0.8400; JB Systems Spiegelkugel 20cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214907a.jpg;;;;;;;;JA;; 1-3 Tage ;12,90;11,50;6,58; JB Systems L2350293;534200562064239; Spiegelkugel 30cm ;2.1300; JB Systems Spiegelkugel 30 cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214956a.jpg;;;;;;;;JA;; 1-3 Tage ;26,90;23,00;13,72; JB Systems L3302984;545200252024246; Spiegelkugel 40cm ;3.5000; JB Systems Spiegelkugel 40cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324215050a.jpg;;;;;;;;JA;; 1-3 Tage ;54,90;49,00;28,00; JB Systems L9302495;542205056225600; Spiegelkugel 50cm ;5.3900; JB Systems Spiegelkugel 50cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324215122a.jpg;;;;;;;;JA;; 1-3 Tage ;89,00;79,00;45,39; JB Systems But the message box that pops up after FileReadLine contains this: 䅲瑩步汮畭浥爻䕁中䍯摥㭁牴楫敬湡浥㭁牴楫敬来睩捨琻䉥獣桲敩扵湧㭋畲穢敳捨牥楢畮朻䕩来湳捨慦瑥渻呥捨湩獣桥ⵄ慴敮㭂楬搱㭂楬搲㭂楬搳㭂楬搴㭂楬搵㭂楬搶㭂楬搷㭂楬搸㭌楥晥牢慲㬢䱩敦敲扡爠䅢∻噥牳慮摺敩琻≕噐ⵐ牥楳⁩湫氮⁍睓琮∻≐牥楳ㄢ㬢偲敩猲∻䡥牳瑥汬敲ੌ㜳㌵㈷㈻㔴㈰〲㔶〲ㄲ㤻M楮椠䱩杨琠塌刀㬰⸱〰〻J䈠卹獴敭猠卣桷慮敮桡汳汥畣桴攠浩琠塌删䅮獣桬畳献;㬻㭨瑴瀺⼯睷眮數慭灬攮捯洯浥摩愯業慧敳⽯牧⽰楣㈰〷〱ㄴㄵ㌵〰愮橰朻㬻㬻㬻㭊䄻㬀ㄭ㌠呡来;ㄲⰹ〻ㄲⰹ〻㘬㔷㬀䩂⁓祳瑥浳 I've attached both files I use. My guess is, that there's something wrong with the encoding, but I'm not sure how to fix it. Thank you very much for your help - virhonestum Encodingtester.au3 TestFile.csv
  24. IniEx.au3 (INI File Processing Functions) solve many problems, such as the limits of AutoIt Default INI function, and add many other options, since all function work by reference so IniEx.au3 also use less memory, and provide a really good performance in speed #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: IniEx ; AutoIt Version : v3.3.9.22++ ; Language ......: English ; Description ...: INI File Processing Functions ; Author(s) .....: DXRW4E ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_IniClearCache() ;_IniCloseFileEx() ;_IniDeleteEx() ;_IniFileWriteEx() ;_IniGetFileInformationEx() ;_IniGetFileStringData() ;_IniGetSectionNumberEx() ;_IniOpenFileEx() ;_IniOpenFile() ;_IniReadEx() ;_IniReadSectionEx() ;_IniReadSectionNamesEx() ;_IniRenameSectionEx() ;_IniWriteEx() ;_IniWriteSectionEx() ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__GetSeparatorCharacter() ;__IniFileWriteEx() ;__IniGetFileStringData() ;__IniReadSectionEx() ;__IniSaveCache() ;__IniWriteSectionEx() ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Const $INI_STRIPLEADING = 1 ; $STR_STRIPLEADING - strip leading white space Global Const $INI_STRIPTRAILING = 2 ; $STR_STRIPTRAILING - strip trailing white space Global Const $INI_STRIPLEADTRAILING = 3 ; BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING) Global Const $INI_ARRAYDATA = 4 Global Const $INI_ARRAYDATA_NOCOUNT = 8 Global Const $INI_NOWRITEREADONLY = 16 Global Const $INI_FO_UNICODE = 32 ; $FO_UNICODE Global Const $INI_FO_UTF16_LE = 32 ; $FO_UTF16_LE Global Const $INI_FO_UTF16_BE = 64 ; $FO_UTF16_BE Global Const $INI_FO_UTF8 = 128 ; $FO_UTF8 Global Const $INI_FO_UTF8_NOBOM = 256 ; $FO_UTF8_NOBOM Global Const $INI_NOOCCURRENCE = 512 Global Const $INI_MERGE = 1024 Global Const $INI_NOCREATE = 2048 Global Const $INI_APPENDDATA = 4096 Global Const $INI_REPLACEONLY = 8192 Global Const $INI_FO_UTF8_FULL = 16384 ; $FO_UTF8_FULL Global Const $INI_NOOVERWRITE = 32768 Global Const $INI_OVERWRITEALL = 65536 Global Const $INI_IGNOREDUPLICATE = 131072 Global Const $INI_DELETE = 262144 Global Const $INI_RENAME = 524288 Global Const $INI_REMOVE = 1048576 ;Global Const $INI_RESERVED* = 2097152 ;Global Const $INI_RESERVED* = 4194304 ;Global Const $INI_RESERVED* = 8388608 Global Const $INI_OPEN_EXISTING = 16777216 Global Const $INI_CREATEPATH = 33554432 Global Const $INI_REPAIR_ERROR = 67108864 Global Const $INI_DISCARDCHANGES = 134217728 Global Const $INI_OPEN_FILEQUEUE = 268435456 ;Global Const $INI_RESERVED* = 536870912 Global Const $INI_2DARRAYFIELD = 1073741824 ;;;; THESE ARE SPECIAL FLAGS, ARE USED INTERNALLY ONLY ;;;; Global Const $INI_INTERNAL_USE_ONLY = 2147483648 Global Const $INI_FO_STYLE = BitOR(31, $INI_OPEN_EXISTING, $INI_CREATEPATH, $INI_REPAIR_ERROR, $INI_OPEN_FILEQUEUE) Global Const $INI_MERGE_NOOCCURRENCE = BitOR($INI_MERGE, $INI_NOOCCURRENCE) Global Const $INI_REMOVE_RENAME = BitOR($INI_REMOVE, $INI_RENAME) Global Const $INI_REMOVE_DELETE = BitOR($INI_REMOVE, $INI_DELETE) Global Const $INI_NOCREATE_REMOVE_DELETE = BitOR($INI_NOCREATE, $INI_REMOVE, $INI_DELETE) Global Const $INI_NOOCCURRENCE_IGNOREDUPLICATE = BitOr($INI_NOOCCURRENCE, $INI_IGNOREDUPLICATE) Global Const $INI_OVERWRITEALL_APPENDDATA = BitOR($INI_OVERWRITEALL, $INI_APPENDDATA) Global Const $NULL_REF = Null Global Const $sINI_OPENFILE_EX = @LF & "[]" & @LF ;;;; DO NOT EVER USE\CHANGE\EDIT THESE VARIABLES ;;;; ;;;; THESE VARIABLES ARE USED INTERNALLY ONLY ;;;; Global Static $INI_NULL_REF = Null Global Static $_HINI[11][11] = [[10, 0]] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFileEx ; Description ...: The _IniOpenFileEx function opens an INI file and returns a handle to it. ; Syntax.........: _IniOpenFileEx($sFilePath[, $iFlags]]) ; Parameters ....: $sFilePath - INI File Path ; $iFlags - Optional, (add the flags together for multiple operations): ; This Flags will be ignored if the $INI_CREATEPATH is not set\used ; | A file may fail to open due to access rights or attributes. ; | The default mode when writing text is ANSI - use the unicode flags to change this. When writing unicode files ; | the Windows default mode (and the fastest in AutoIt due to the least conversion) is UTF16 Little Endian (mode 32). ; | $INI_FO_* Flags will be ignored if the $INI_CREATEPATH is not Set\Used ; |$INI_FO_UNICODE or $INI_UTF16_LE (32) - Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM. ; |$INI_FO_UTF16_BE (64) - Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM. ; |$INI_FO_UTF8 (128) - Use Unicode UTF8 (with BOM) reading and writing mode. Reading does not override existing BOM. ; |$INI_FO_UTF8_NOBOM (256) - Use Unicode UTF8 (without BOM) reading and writing mode. ; |$INI_FO_UTF8_FULL (16384) - When opening for reading and no BOM is present, use full file UTF8 detection. If this is not used then only the initial part of the file is checked for UTF8. ; ;;;;;;;;;;;; ; |$INI_OPEN_EXISTING (16777216) - If the INI File (Path) is Already Open use that (Handle) (Default Always Opens a New) ; |$INI_CREATEPATH (33554432) - Create INI File if does not exist (Default if file not exist Return Error) ; |$INI_REPAIR_ERROR (67108864) - If exist Error when Opening the INI File Repair Error, example as this line (@CRLF & [SectionName & @CRLF) repair in (@CRLF & [SectionName] & @CRLF), Default Return Error ; |$INI_OPEN_FILEQUEUE (268435456) - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file ; Return values .: Success - INI Handle ; Failure - Returns 0 or String\Text of error line (check @Extended for error line number) ; @Error - 0 = No error. ; |1 = File cannot be opened or found. ; |2 = Error when Opening the INI File ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniOpenFileEx($sFilePath, $iFlags = 0) If BitAND($iFlags, $INI_OPEN_EXISTING) Then For $i = 1 To $_HINI[0][0] If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i) Next EndIf Local $sCS, $_sCS = "\r", $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE) If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r(?!\n)', @CRLF) ;;;;, '(?<!\r)\n', @CRLF) $sFilePath = "FileQueue" $iFileEncoding = $iFO_Style ;;(StringIsASCII($aFileData) ? 0 : 32) Else $hFilePath = FileOpen($sFilePath) If $hFilePath = -1 Then If Not FileExists($sFilePath) Then If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0) $iFO_Style += 10 ;;$iFO_Style = 42 EndIf $hFilePath = FileOpen($sFilePath, $iFO_Style) If $hFilePath = -1 Then Return SetError(1, 0, 0) EndIf $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r(?!\n)', @CRLF) ;;;;, '(?<!\r)\n', @CRLF) $iFileEncoding = FileGetEncoding($hFilePath) FileClose($hFilePath) EndIf $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1) If Not @Error Then Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1) If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0]) $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\r\n]*)(?=[\r\n]|$)', "$1]") EndIf $sCS = __GetSeparatorCharacter($aFileData) If $sCS = @CR Then $_sCS = "" $aFileData = StringRegExpReplace($aFileData & @CRLF & "[", "\n\K(?>[" & $_sCS & "\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)", $sCS & "${0}" & $sCS) $aFileData = StringRegExp($aFileData & $sCS, $sCS & "([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[" & $_sCS & "\n\h\f\xb\x0]*\n)*)([^" & $sCS & "]*)" & $sCS & "([^" & $sCS & "]*)", 3) $aFileData[0] = UBound($aFileData) - 1 If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 2) For $iHINI = 1 To $_HINI[0][0] If Not $_HINI[$iHINI][0] Then ExitLoop Next If $iHINI > $_HINI[0][0] Then ReDim $_HINI[$iHINI + $iHINI][11] $_HINI[0][0] = $iHINI + $iHINI - 1 EndIf $aFileData[2] = $iHINI If Not $_sCS Then $aFileData[3] = StringAddCR($aFileData[3]) $aFileData[4] = StringAddCR($aFileData[4]) $aFileData[5] = StringAddCR($aFileData[5]) EndIf For $i = 7 To $aFileData[0] Step 6 $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i If Not $_sCS Then $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1]) $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2]) $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3]) $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4]) EndIf Next $_HINI[0][1] += 1 ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1 $_HINI[$iHINI][0] = $iHINI $_HINI[$iHINI][1] = $aFileData $_HINI[$iHINI][2] = $sFilePath $_HINI[$iHINI][3] = $iFileEncoding $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6 $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1) $_HINI[$iHINI][7] = Null Return $iHINI EndFunc ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniOpenFile ; Description ...: The _IniOpenFile function opens an INI file and returns a handle to it. ; Parameters ....: the same as the _IniOpenFileEx(), See _IniOpenFileEx() ; Return values .: See _IniOpenFileEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: _IniOpenFile() is the same as the _IniOpenFileEx(), only that _IniOpenFile() force the check\repair of @CR or @LF in @CRLF ; performance\speed does not change much with _IniOpenFileEx(), _IniOpenFile() can only be about 1% or 5% or10% slower ; =============================================================================================================================== Func _IniOpenFile($sFilePath, $iFlags = 0) If BitAND($iFlags, $INI_OPEN_EXISTING) Then For $i = 1 To $_HINI[0][0] If $_HINI[$i][2] = $sFilePath Then Return SetError(0, $i, $i) Next EndIf Local $hFilePath, $iFileEncoding, $aFileData, $aErrorLine, $iFO_Style = BitXOR(BitOR($iFlags, $INI_FO_STYLE), $INI_FO_STYLE) If BitAND($iFlags, $INI_OPEN_FILEQUEUE) Then $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & $sFilePath, '\r\n?', @LF) $sFilePath = "FileQueue" $iFileEncoding = $iFO_Style ;;(StringIsASCII($aFileData) ? 0 : 32) Else $hFilePath = FileOpen($sFilePath) If $hFilePath = -1 Then If Not FileExists($sFilePath) Then If Not BitAND($iFlags, $INI_CREATEPATH) Then Return SetError(1, 0, 0) $iFO_Style += 10 ;;$iFO_Style = 42 EndIf $hFilePath = FileOpen($sFilePath, $iFO_Style) If $hFilePath = -1 Then Return SetError(1, 0, 0) EndIf $aFileData = StringRegExpReplace($sINI_OPENFILE_EX & FileRead($hFilePath), '\r\n?', @LF) $iFileEncoding = FileGetEncoding($hFilePath) FileClose($hFilePath) EndIf $aErrorLine = StringRegExp($aFileData, '\n\K[\h\f\xb\x0]*\[[^\]\n]*(?:\n|$)', 1) If Not @Error Then Local $iErrorLine = @Extended - (StringLen($aErrorLine[0]) - 1) If Not BitAND($iFlags, $INI_REPAIR_ERROR) Then Return SetError(2, StringSplit(StringLeft($aFileData, $iErrorLine), @LF)[0] - 2, $aErrorLine[0]) $aFileData = StringRegExpReplace($aFileData, '(\n[\h\f\xb\x0]*\[[^\]\n]*)(?=\n|$)', "$1]") EndIf $aFileData = StringRegExpReplace($aFileData & @LF & "[", '\n\K(?>[\n\h\f\xb\x0]*\n|\x0*)(?=[\h\f\xb\x0]*\[)', @CR & "${0}" & @CR) $aFileData = StringRegExp($aFileData & @CR, '\r([\h\f\xb\x0]*\[)([^\]\n]*)(\][^\n]*\n)((?>[\n\h\f\xb\x0]*\n)*)([^\r]*)\r([^\r]*)', 3) $aFileData[0] = UBound($aFileData) - 1 If $aFileData[0] < 5 Then Return SetError(1, 0, 0) ; should not happen ever $aFileData[$aFileData[0]] = StringTrimRight($aFileData[$aFileData[0]], 1) For $iHINI = 1 To $_HINI[0][0] If Not $_HINI[$iHINI][0] Then ExitLoop Next If $iHINI > $_HINI[0][0] Then ReDim $_HINI[$iHINI + $iHINI][11] $_HINI[0][0] = $iHINI + $iHINI - 1 EndIf $aFileData[2] = $iHINI $aFileData[3] = StringAddCR($aFileData[3]) $aFileData[4] = StringAddCR($aFileData[4]) $aFileData[5] = StringAddCR($aFileData[5]) For $i = 7 To $aFileData[0] Step 6 $_HINI[$iHINI][5] &= @LF & $aFileData[$i] & @CR & $i $aFileData[$i + 1] = StringAddCR($aFileData[$i + 1]) $aFileData[$i + 2] = StringAddCR($aFileData[$i + 2]) $aFileData[$i + 3] = StringAddCR($aFileData[$i + 3]) $aFileData[$i + 4] = StringAddCR($aFileData[$i + 4]) Next $_HINI[0][1] += 1 ;;($_HINI[0][1] < 1) ? 1 : $_HINI[0][1] + 1 $_HINI[$iHINI][0] = $iHINI $_HINI[$iHINI][1] = $aFileData $_HINI[$iHINI][2] = $sFilePath $_HINI[$iHINI][3] = $iFileEncoding $_HINI[$iHINI][4] = ($aFileData[0] - 5) / 6 $_HINI[$iHINI][5] = StringReplace($_HINI[$iHINI][5], "\E", "\e", 0, 1) $_HINI[$iHINI][7] = Null Return $iHINI EndFunc ;==>_IniOpenFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniCloseFileEx ; Description ...: The _IniCloseFileEx function closes the INI file opened by a call to _IniOpenFileEx. ; Syntax.........: _IniCloseFileEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle or INI Path to the INI file to be closed, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; if $hIniFile is NULL Function Close All Open Handle or INI Path ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |Default - always Commits the changes that were made when the INI file was opened by _IniOpenFileEx() ; |$INI_DISCARDCHANGES (134217728) - Discards the changes that were made when the INI file was opened by _IniOpenFileEx() ; Return values .: NONE ; Author ........: DXRW4E ; Remarks .......: ; =============================================================================================================================== Func _IniCloseFileEx($hIniFile, $iFlags = 0) If $hIniFile = $NULL_REF Then For $i = 1 To $_HINI[0][0] If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$i][2] <> "FileQueue" Then _IniFileWriteEx($i, $iFlags) For $y = 0 To 10 $_HINI[$i][$y] = "" Next Next $_HINI[0][1] = 0 Else $hIniFile = _IniGetFileInformationEx($hIniFile) If @Error Then Return SetError(1, 0, 0) If Not BitAND($iFlags, $INI_DISCARDCHANGES) And $_HINI[$hIniFile][2] <> "FileQueue" Then _IniFileWriteEx($hIniFile, $iFlags) For $i = 0 To 10 $_HINI[$hIniFile][$i] = "" Next $_HINI[0][1] -= 1 EndIf Return 0 EndFunc ;==>_IniCloseFileEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniDeleteEx ; Description ...: Delete\Remove - Section\KeyName in INI File. ; Syntax.........: _IniDeleteEx(ByRef $hIniFile, $sSectionName[, $sKeyName[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data and $sKeyName the name of the key to delete ; $sKeyName - The key name to delete, If $INI_OVERWRITEALL if set\used, $sKeyName will be writte exactly as in $sKeyName (without Edit\Formatting) ; This parameter can be NULL (use the $NULL_REF to set NULL this parameter), If $sKeyName is NULL, $hIniFile must be contain INI String\Text Data and $sSectionName the name of the section to delete ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_NOOCCURRENCE (512) - Check only first section if there are more than one ; |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ; |$INI_DELETE (262144) - Delete\Remove KeyName\Value\Data ; |$INI_REMOVE (1048576) - Remove\Delete Section ; $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName not found ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniDeleteEx(ByRef $hIniFile, $sSectionName, $sKeyName = "", $iFlags = 0, $scKeyName = "=") If Not $scKeyName Then $scKeyName = "=" If $sSectionName = $NULL_REF Then Local $iOffSet = StringInStr($hIniFile, @LF, 1) If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "") $hIniFile = StringTrimLeft($hIniFile, $iOffSet) SetExtended(1) Else $hIniFile = StringRegExpReplace($hIniFile, '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*', "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) EndIf ElseIf $sKeyName = $NULL_REF Then ;Not Recommended (NOT SAFE), if the Section (contains) String\Text Data is greater than 4.5 MB, the Section will be ignored $hIniFile = StringTrimRight(StringRegExpReplace($hIniFile & @LF & "[", "(?is)\n[\h\f\xb\x0]*\[\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E\][^\n]*(?>\n?(?![\h\f\xb\x0]*\[))(.*?(?=\n[\h\f\xb\x0]*\[))", "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)), 2) Else If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") ;;;;If Not $sSectionName Then Return SetError(2, 0, "") ;Invalid Section Name If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) If Not $sKeyName Or BitAND($iFlags, $INI_REMOVE_DELETE) = $INI_REMOVE Then $iFlags = BitOr($iFlags, $INI_REMOVE) __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1]) Else $iFlags = BitOR(BitAND($iFlags, $INI_NOOCCURRENCE_IGNOREDUPLICATE), $INI_DELETE, $INI_MERGE) If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) If @Error Then Return SetError(3, 0, "") EndIf Local $aKeyValue[2][3] = [[1],[$sKeyName]] __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1]) EndIf EndIf Return SetError(0, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadEx ; Description ...: The _IniReadEx Retrieves a string from the specified section in an Ini file ; Syntax.........: _IniReadEx($hIniFile, $sSectionName, $sKeyName[, $sDefault[, $iFlags[, $scKeyName]]]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionName - The name of the section containing the key name, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ; $sKeyName - The name of the key whose associated string is to be retrieved ; $sDefault - The default value to return if the requested KeyName is not found. ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_ARRAYDATA (4) - Read All KeyName and Return Array of ValueString ; |$INI_ARRAYDATA_NOCOUNT (8) - Disable the return count in the first element, This Flags will be ignored if the $INI_ARRAYDATA is not set\used ; |$INI_NOOCCURRENCE (512) - Read only first section if there are more than one ; |$INI_MERGE (1024) - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ; $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: The first occurrence of requested key value as a string Or Array of Value String ; Failure - Returns $sDefault parameter ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName not found ; |5 = Invalid KeyName ; |6 = KeyName not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sDefault = "", $iFlags = 0, $scKeyName = "=") ;;If Not $sKeyName Then Return SetError(5, 0, "") If StringInStr($sKeyName, "\E", 1) Then $sKeyName = StringReplace($sKeyName, "\E", "\e", 0, 1) Local $aValueString, $sValueString, $iArray = BitAND($iFlags, $INI_ARRAYDATA) If $sSectionName = $NULL_REF Then $aValueString = StringRegExp(StringLeft($hIniFile, StringInStr($hIniFile, @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1) Else If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then _IniReadSectionEx($hIniFile, $sSectionName, BitOR($iFlags, $INI_STRIPLEADTRAILING)) If @Error Then Return SetError(3, 0, "") EndIf $aValueString = StringRegExp(StringLeft(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], StringInStr(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], @LF, 1)), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 1) ;;;;$aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '(?im)^[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', 3) EndIf If Not @Error Then If Not $iArray Then Return $aValueString[0] $sValueString = $aValueString[0] & @LF EndIf $aValueString = StringRegExp(($sSectionName = $NULL_REF ? $hIniFile : ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]]), '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$)', ($iArray ? 3 : 1)) If @Error Then Return SetError(6, 0, $sDefault) If Not $iArray Then Return $aValueString[0] For $i = 0 To UBound($aValueString) - 1 $sValueString &= $aValueString[$i] & @LF Next Return StringSplit(StringTrimRight($sValueString, 1), @LF, (BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) ? 3 : 1)) EndFunc ;==>_IniReadEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionEx ; Description ...: The _IniReadSectionEx Retrieves all the lines for the specified section ; Syntax.........: _IniReadSectionEx(ByRef $hIniFile, $sSectionName[, $iFlags[, $scKeyName]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; Default Return Section String\Text Data ; |$INI_NOOCCURRENCE (512) - Read only first section if there are more than one ; |$INI_MERGE (1024) - Join section if more than one in INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ; |$INI_2DARRAYFIELD (1073741824) - Return 2DArray ; $aArray[0][0] = number of elements ; $aArray[0][1] = Key-Name separator character, Defaut is '=' ; $aArray[1][0] = "KeyName" ; $aArray[1][1] = "Value" ; $aArray[1][2] = "Unmodified contents of a line (example ' KeyName = Value')" ; $aArray[n][0] = "KeyName" ; $aArray[n][1] = "Value" ; $aArray[n][2] = "Unmodified contents of a line (example ' KeyName = Value')" ; $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: String\Text Data Or 2D Array ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName's not found ; |4 = Array is invalid, Key\Value not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionEx(ByRef $hIniFile, $sSectionName, $iFlags = 0, $scKeyName = "=") If Not $scKeyName Then $scKeyName = "=" If $sSectionName = $NULL_REF Then Local $_aSectionData = StringRegExp($hIniFile, '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3) Else If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then $iFlags = BitOR($iFlags, $INI_NOCREATE) __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) If @Error Then Return SetError(3, 0, "") EndIf If Not BitAND($iFlags, $INI_2DARRAYFIELD) Then Return ($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]] Local $_aSectionData = StringRegExp(($_HINI[$hIniFile][1])[$_HINI[$hIniFile][10]], '(?m)^((?>[\h\f\xb\x0]*)((?>"[^"\r\n]+"|(?:[^"\s' & $scKeyName & '\x0]+|(?>[\h\f\xb\x0]+)(?!' & $scKeyName & '))*))(?>[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*)(?|"([^\r\n]*)"|(.*?))[\h\f\xb\x0]*(?=[\r\n]|$))', 3) EndIf If @Error Then Return SetError(4, 0, "") Local $iaSectionData = UBound($_aSectionData), $aSectionData[$iaSectionData / 3 + 1][3] = [[0,$scKeyName,$iaSectionData - 1]] For $i = 0 To $aSectionData[0][2] Step 3 $aSectionData[0][0] += 1 $aSectionData[$aSectionData[0][0]][0] = $_aSectionData[$i + 1] $aSectionData[$aSectionData[0][0]][1] = $_aSectionData[$i + 2] $aSectionData[$aSectionData[0][0]][2] = $_aSectionData[$i] Next Return SetError(0, $aSectionData[0][0], $aSectionData) EndFunc ;==>_IniReadSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniReadSectionNamesEx ; Description ...: The _IniReadSectionNamesEx Retrieves the names of all sections in an INI file ; Syntax.........: _IniReadSectionNamesEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $iFlags - Optional, Flag to indicate the type of action that should be performed ; |$INI_ARRAYDATA_NOCOUNT (8) - disable the return count in the first element ; |$NULL_REF (NULL) - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Array of SectionNames String, and set @Extended = Number of Section's ; @Error - 0 = No error. ; |1 = Array is invalid, Invalid IniHandle. ; |3 = Array is invalid, SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniReadSectionNamesEx(ByRef $hIniFile, $iFlags = 0) If $iFlags = $NULL_REF Then Local $aSectionNames, $iANC = BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) $aSectionNames = StringRegExp(($iANC ? @LF : @LF & "[]" & @LF) & $hIniFile, "\n[\h\f\xb\x0]*\[([^\r\n]*)\]", 3) If @Error Then Return SetError(1, 0, "") If $iANC Then Return SetError(0, UBound($aSectionNames), $aSectionNames) $aSectionNames[0] = UBound($aSectionNames) - 1 Return SetError(0, $aSectionNames[0], $aSectionNames) EndIf If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") If Not $_HINI[$hIniFile][4] Then Return SetError(3, 0, "") If BitAND($iFlags, $INI_ARRAYDATA_NOCOUNT) Then Return SetError(0, $_HINI[$hIniFile][4], StringRegExp($_HINI[$hIniFile][5], "\n([^\r\n]*)", 3)) Return SetError(0, $_HINI[$hIniFile][4], StringRegExp(@LF & $_HINI[$hIniFile][4] & $_HINI[$hIniFile][5], "\n([^\r\n]*)", 3)) EndFunc ;==>_IniReadSectionNamesEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniRenameSectionEx ; Description ...: The _IniRenameSectionEx rename the sections in an INI file ; Syntax.........: _IniRenameSectionEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_NOOCCURRENCE (512) - Rename only first section if there are more than one ; |$INI_MERGE (1024) - Join section if more than one in INI\INI file, This Flag will be ignored if the $INI_NOOCCURRENCE is set\used ; |$NULL_REF (NULL) - $hIniFile must be contain INI String\Section\Key\Value\Data ; Return values .: Returns a 0 (check @Extended for number of edit performed) ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniRenameSectionEx(ByRef $hIniFile, $sSectionName, $sNewSectionName, $iFlags = 0) ;;;;If Not $sSectionName Or Not $sNewSectionName Then Return SetError(2, 0, "") ;Invalid Section Name If $iFlags = $NULL_REF Then $hIniFile = StringRegExpReplace($hIniFile, "(?mi)^[\h\f\xb\x0]*\[\K\Q" & StringReplace($sSectionName, "\E", "\e", 0, 1) & "\E(?=\])", StringReplace($sNewSectionName, "\", "\\", 0, 1), (BitAND($iFlags, $INI_NOOCCURRENCE) ? 1 : 0)) Else If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) $iFlags = BitXOR(BitOR($iFlags, $INI_REMOVE_RENAME), $INI_REMOVE) If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0) __IniWriteSectionEx($hIniFile, $sSectionName, $sNewSectionName, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1]) EndIf Return SetError(@Error, @Extended, 0) EndFunc ;==>_IniRenameSectionEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteEx ; Description ...: Write\Add\Replace\Delete\Change\Edit a KeyName\Value\Data in INI File ; Syntax.........: _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue[, $iFlags[, $scKeyName]]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ; $sKeyName - The key name in the in the .ini file. ; $sKeyName - The value to write/change. ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_STRIPLEADING (1) - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ; |$INI_STRIPTRAILING (2) - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ; |$INI_NOOCCURRENCE (512) - Check only first section if there are more than one ; |$INI_NOCREATE (2048) - Not Create New Section If Section Not Exist ; |$INI_APPENDDATA (4096) - Add KeyName\Value\Data (Append Mod) ; |$INI_REPLACEONLY (8192) - Add KeyName\Value\Data Only if Exist ; |$INI_NOOVERWRITE (32768) - Add KeyName\Value\Data Only if Not Exist ; |$INI_OVERWRITEALL (65536) - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ; |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ; |$INI_DELETE (262144) - Delete\Remove KeyName\Value\Data ; $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName's not found ; |5 = Invalid KeyName ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteEx(ByRef $hIniFile, $sSectionName, $sKeyName, $sValue, $iFlags = 0, $scKeyName = "=") ;;If Not $sKeyName Then Return SetError(5, 0, "") If Not $scKeyName Then $scKeyName = "=" If $sSectionName = $NULL_REF Then If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = "" $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF Else Local $asKeyValue, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1) $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*' If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $sKeyName & '"\E|\Q' & $sKeyName & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "") If BitAND($iFlags, $INI_DELETE) Then $hIniFile = StringTrimLeft($hIniFile, $iOffSet) ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then $hIniFile = $sKeyName & $scKeyName & $sValue & @CRLF & StringTrimLeft($hIniFile, $iOffSet) EndIf ElseIf BitAND($iFlags, $INI_DELETE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) Else $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1) $iOffSet = @Extended - 1 If Not @Error Then If BitAND($iFlags, $INI_NOOVERWRITE) Then If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "") Else $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $sKeyName & $scKeyName & $sValue & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")) EndIf ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then $hIniFile &= $sKeyName & $scKeyName & $sValue & @CRLF Else Return SetError(0, 0, 0) EndIf EndIf EndIf Return SetError(0, 1, 0) Else If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") ;;;;If Not $sSectionName Then Return SetError(2, 0, "") ;Invalid Section Name If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) Local $aKeyValue[2][3] = [[1],[$sKeyName,"",$sKeyName & $scKeyName & $sValue]] $iFlags = BitOR(BitXOR($iFlags, BitAND($iFlags, $INI_REMOVE_RENAME)), $INI_MERGE) If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) If @Error Then Return SetError(3, 0, "") EndIf __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1]) EndIf Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniWriteSectionEx ; Description ...: Add\Replace\Delete\Remove\Rename\Change\Edit a Section\KeyName\Value\Data in INI File. ; Syntax.........: _IniWriteSectionEx() ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionName - The name of the section containing the Key\Value\Data ; $aKeyValue - String\Text Data (example 'KeyName=Value 7 @LF & KeyName2=Value2') or an 2DArray is passed as data, the return Array of IniReadSectionEx() can be used immediately. ; If $aKeyValue is String\Text Data and $INI_OVERWRITEALL or $INI_APPENDDATA if Set\Used, $aKeyValue will be writte exactly as in $aKeyValue (without Edit\Formatting) ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_STRIPLEADING (1) - strip leading white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ; |$INI_STRIPTRAILING (2) - trailing white space Section, This Flag will be ignored if the $INI_OVERWRITEALL or $INI_APPENDDATA is set\used ; |$INI_NOOCCURRENCE (512) - Check only first section if there are more than one ; |$INI_NOCREATE (2048) - Not Create New Section If Section Not Exist ; |$INI_APPENDDATA (4096) - Add KeyName\Value\Data (Append Mod) ; |$INI_REPLACEONLY (8192) - Add KeyName\Value\Data Only if Exist ; |$INI_NOOVERWRITE (32768) - Add KeyName\Value\Data Only if Not Exist ; |$INI_OVERWRITEALL (65536) - Overwrite All data in Section (Replaces all KeyName\Value\Data in the Section) ; |$INI_IGNOREDUPLICATE (131072) - Proceed\Execute (Add\Delete\Replace\Edit ect ect) Once Only (Ignore all other Duplicate\Occurrences of KeyName\Value\Data) ; |$INI_DELETE (262144) - Delete\Remove KeyName\Value\Data ; |$INI_RENAME (524288) - Renames a section ; |$INI_REMOVE (1048576) - Remove\Delete Section ; $scKeyName - Optional, Key-Name separator character, Default is '=', This parameter can not be '"' or @CR or @LF ; Return values .: Returns a 0 (check @Extended for number of edit performed) ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName's not found ; |5 = Invalid KeyName ; Remarks .......: ; Author ........: DXRW4E ; Remarks .......: $INI_MERGE (1024) - (Join section if more than one in INI file) is always set\used by default, to disable it just use the $INI_NOOCCURRENCE ; =============================================================================================================================== Func _IniWriteSectionEx(ByRef $hIniFile, $sSectionName, $aKeyValue, $iFlags = 0, $scKeyName = "=") ;~ If $sSectionName = $NULL_REF Then ;~ If Not $scKeyName Then $scKeyName = "=" ;~ If IsArray($aKeyValue) Then ;~ Local $iCols = UBound($aKeyValue, 2) ;~ If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(7, 0, "") ;~ If $iCols = 2 Then ;~ ReDim $aKeyValue[$aKeyValue[0][0] + 1][3] ;~ For $i = 1 To $aKeyValue[0][0] ;~ $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1] ;~ Next ;~ EndIf ;~ ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~ $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName) ;~ If @Error Then Return SetError(7, 0, "") ;~ EndIf ;~ If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then ;~ If BitAND($iFlags, $INI_OVERWRITEALL) Then $hIniFile = "" ;~ If IsArray($aKeyValue) Then ;~ For $i = 1 To $aKeyValue[0][0] ;~ $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~ Next ;~ Else ;~ ;; KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect) ;~ $hIniFile &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF) ;~ EndIf ;~ Return SetError(0, 1, 0) ;~ Else ;~ Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($hIniFile, @LF, 1) ;~ For $i = 1 To $aKeyValue[0][0] ;~ $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*' ;~ If StringRegExp(StringLeft($hIniFile, $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then ;~ If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "") ;~ If BitAND($iFlags, $INI_DELETE) Then ;~ $hIniFile = StringTrimLeft($hIniFile, $iOffSet) ;~ ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then ;~ $hIniFile = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($hIniFile, $iOffSet) ;~ EndIf ;~ ElseIf BitAND($iFlags, $INI_DELETE) Then ;~ $hIniFile = StringRegExpReplace($hIniFile, $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) ;~ Else ;~ $asKeyValue = StringRegExp($hIniFile, $sKNPattern, 1) ;~ $iOffSet = @Extended - 1 ;~ If Not @Error Then ;~ If BitAND($iFlags, $INI_NOOVERWRITE) Then ;~ If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $hIniFile = StringLeft($hIniFile, $iOffSet) & StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "") ;~ Else ;~ $hIniFile = StringLeft($hIniFile, $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($hIniFile, $iOffSet) : StringRegExpReplace(StringTrimLeft($hIniFile, $iOffSet), $sKNPattern, "")) ;~ EndIf ;~ ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then ;~ $hIniFile &= $aKeyValue[$i][2] & @CRLF ;~ Else ;~ $iKeyValue -= 1 ;~ EndIf ;~ EndIf ;~ $iKeyValue += 1 ;~ Next ;~ Return SetError(0, $iKeyValue, 0) ;~ EndIf ;~ EndIf If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") ;;;;If Not $sSectionName Then Return SetError(2, 0, "") ;Invalid Section Name If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) If BitAND($iFlags, $INI_REMOVE) Then __IniWriteSectionEx($hIniFile, $sSectionName, $INI_NULL_REF, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1]) ElseIf BitAND($iFlags, $INI_RENAME) Then ;;;; $aKeyValue is New Section Name ;;If Not $aKeyValue Then Return SetError(5, 0, "") If BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE And Not __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) Then Return SetError(3, 0, 0) __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $INI_NULL_REF, $_HINI[$hIniFile][1]) Else If Not $scKeyName Then $scKeyName = "=" If IsArray($aKeyValue) Then Local $iCols = UBound($aKeyValue, 2) If UBound($aKeyValue, 0) <> 2 Or $iCols < 2 Then Return SetError(5, 0, "") If $iCols = 2 Then ReDim $aKeyValue[$aKeyValue[0][0] + 1][3] For $i = 1 To $aKeyValue[0][0] $aKeyValue[$i][2] = $aKeyValue[$i][0] & $scKeyName & $aKeyValue[$i][1] Next EndIf ElseIf Not BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then $aKeyValue = _IniReadSectionEx($aKeyValue, Null, $INI_2DARRAYFIELD, $scKeyName) If @Error Then Return SetError(5, 0, "") EndIf $iFlags = BitOR($iFlags, $INI_MERGE) If $_HINI[$hIniFile][7] <> $sSectionName Or ($_HINI[$hIniFile][8] > 1 And BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) <> BitAND($_HINI[$hIniFile][9], $INI_MERGE_NOOCCURRENCE)) Then __IniReadSectionEx($hIniFile, $sSectionName, $iFlags, $_HINI[$hIniFile][1]) If @Error Then Return SetError(3, 0, "") EndIf __IniWriteSectionEx($hIniFile, $sSectionName, $aKeyValue, $iFlags, $scKeyName, $_HINI[$hIniFile][1]) EndIf Return SetError(@Error, @Extended, 0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetSectionNumberEx ; Description ...: The _IniGetSectionNumberEx Retrieves the number of all sections in an INI file ; Syntax.........: _IniGetSectionNumberEx(Byref $hIniFile) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: Number of Section's ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |3 = SectionName's not found ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetSectionNumberEx(ByRef $hIniFile) If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Local $aSectionNames = StringRegExp(@LF & $hIniFile, "\n[\h\f\xb\x0]*\[[^\r\n]*\K\]", 3) ;StringRegExp($hIniFile, "(?m)^[\h\f\xb\x0]*\[[^\r\n]*\]", 3) Return SetError(@Error, 0, UBound($aSectionNames)) EndIf Return SetError(($_HINI[$hIniFile][4] ? 0 : 3), 0, $_HINI[$hIniFile][4]) EndFunc ;==>_IniGetSectionNumberEx ; #FUNCTION# =========================================================================================================== ; Name...........: _IniGetFileInformationEx ; Description ...: Returns information about an INI file ; Syntax.........: _IniGetFileInformationEx($hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle of INI file previously opened by _IniOpenFileEx, see _IniOpenFileEx() ; $iFlags - Optional ; |0 - Return INI Handle (Default) ; |1 - Return INI File Array Data (is array of arrays) ; |2 - Return INI File Path ; |3 - Return INI Encoding ; |4 - Return INI Section Number ; Return values .: See Flag parameter ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: ; =============================================================================================================================== Func _IniGetFileInformationEx($hIniFile, $iFlags = 0) If Not $hIniFile Then Return SetError(1, 0, "") If $_HINI[0][1] < 0 Then $_HINI[0][1] = 0 Return SetError(1, 0, "") ElseIf IsString($hIniFile) Then ;;If StringIsDigit($hIniFile) And StringLeft($hIniFile, 1) <> "0" Then ;; $hIniFile = Number($hIniFile) ;;Else For $i = 1 To $_HINI[0][0] If $_HINI[$i][2] = $hIniFile Then ExitLoop Next $hIniFile = $i ;;EndIf EndIf If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") ; Or $hIniFile <> $_HINI[$hIniFile][0] If $iFlags < 1 Or $iFlags > 4 Then Return $hIniFile Return SetError(0, $hIniFile, $_HINI[$hIniFile][$iFlags]) EndFunc ;==>_IniGetFileInformationEx ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniGetFileStringData ; Description ...: The _IniGetFileStringData Retrieves all INI Lines\String\Text Data ; Syntax.........: _IniGetFileStringData(ByRef $hIniFile[, $iFlags]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_STRIPLEADING (1) - strip leading white space Section ; |$INI_STRIPTRAILING (2) - strip trailing white space Section ; Return values .: String\Text Data ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniGetFileStringData(ByRef $hIniFile, $iFlags = 0) If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") ;;Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING) ;;$sData = ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5]) ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6 ;; $sData &= ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5]) ;;Next Local $sData = __IniGetFileStringData($hIniFile, $iFlags, $_HINI[$hIniFile][1]) Return SetError(0, $_HINI[$hIniFile][3], $sData) EndFunc ;==>_IniGetFileStringData ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniClearCache ; Description ...: Clear INI File Processing Functions Cache ; Syntax.........: _IniClearCache(ByRef $aIniFile) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is useful to Run after _IniRea*Ex Funcion's, only in the case when in the INI file are duplicated function ; and if the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used, because in this case the _IniReadEx\_IniReadSectionEx saves ; in cache the Function's\String\Data to be fast during the loop ect ect, so only in cases when you Get\Read Occurrence Function ; and the flag $INI_MERGE or $INI_NOOCCURRENCE is not set\used ; All other function as _IniDeleteEx or _IniWrite*Ex use by Default or Force the use of $INI_MERGE flag ; So in 99.9% of cases you do not Need\Have to run _IniClearCache(), because the INI File Processing Functions Work's only By Reference ; =============================================================================================================================== Func _IniClearCache(ByRef $hIniFile) If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") $_HINI[$hIniFile][6] = "" __IniSaveCache($hIniFile, $_HINI[$hIniFile][6], $INI_NULL_REF, $_HINI[$hIniFile][6], $_HINI[$hIniFile][6], $_HINI[$hIniFile][1]) Return 0 EndFunc ;==>_IniClearCache ; #FUNCTION# ==================================================================================================================== ; Name...........: _IniFileWrite ; Description ...: Write a Ini File ; Syntax.........: _IniFileWriteEx(ByRef $hIniFile[, $iFlags[, $sFilePath[, $iFileEncoding]]]) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $iFlags - Optional, Flag to indicate the type of action that should be performed (add the flags together for multiple operations): ; |$INI_STRIPLEADING (1) - strip leading white space Section ; |$INI_STRIPTRAILING (2) - trailing white space Section ; |$INI_NOWRITEREADONLY (16) - Do not Write\Replace\Edit the ReadOnly file (Default Write\Replace\Edit the ReadOnly files) ; $sFilePath - Optional, use alternative FilePath, By Default always is used (Default) PathFile ; $iFileEncoding - Optional, use alternative FileEncoding, By Default always is used (Default) FileEncoding ; Return values .: Returns a 0 ; @Error - 0 = No error. ; |1 = Invalid IniHandle. ; |9 = Invalid FilePath ; |10 = A file may fail to open due to access rights or attributes. ; Remarks .......: ; Author ........: DXRW4E ; =============================================================================================================================== Func _IniFileWriteEx(ByRef $hIniFile, $iFlags = 0, $sFilePath = Default, $iFileEncoding = Default) If $hIniFile < 1 Or $hIniFile > $_HINI[0][0] Then Return SetError(1, 0, "") If $_HINI[$hIniFile][2] = "FileQueue" And Not $sFilePath Then Return SetError(9, 0, "") If $sFilePath = Default Then $sFilePath = $_HINI[$hIniFile][2] If $iFileEncoding = Default Then $iFileEncoding = $_HINI[$hIniFile][3] + 10 ;;Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING) ;;$hFileOpen = FileOpen($_HINI[$hIniFile][2], $_HINI[$hIniFile][3] + 10) ;; ;; Check if file opened for writing OK ;;If $hFileOpen = -1 Then ;; Return SetError(10, 0, 0) ;;EndIf ;;FileWrite($hFileOpen, ($iSL ? "" : ($_HINI[$hIniFile][1])[3]) & ($_HINI[$hIniFile][1])[4] & ($iST ? "" : ($_HINI[$hIniFile][1])[5])) ;;For $i = 6 To ($_HINI[$hIniFile][1])[0] Step 6 ;; FileWrite($hFileOpen, ($_HINI[$hIniFile][1])[$i] & ($_HINI[$hIniFile][1])[$i + 1] & ($_HINI[$hIniFile][1])[$i + 2] & ($iSL ? "" : ($_HINI[$hIniFile][1])[$i + 3]) & ($_HINI[$hIniFile][1])[$i + 4] & ($iST ? "" : ($_HINI[$hIniFile][1])[$i + 5])) ;;Next ;;FileClose($hFileOpen) __IniFileWriteEx($hIniFile, $iFlags, $sFilePath, $iFileEncoding, $_HINI[$hIniFile][1]) Return SetError(@Error, @Extended, 0) EndFunc ;==>_IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniReadSectionEx ; Description ...: Support Function for _IniReadSectionEx ; Syntax.........: __IniReadSectionEx(ByRef $aIniFile, ByRef $sSectionName, ByRef $iFlags) ; Parameters ....: See _IniReadSectionEx() ; Return values .: See _IniReadSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniReadSectionEx ; =============================================================================================================================== Func __IniReadSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $iFlags, ByRef $aIniFile) ;;;;If Not $sSectionName Then Return SetError(2, 0, "") ;Invalid Section Name If StringInStr($sSectionName, "\E", 1) Then $sSectionName = StringReplace($sSectionName, "\E", "\e", 0, 1) Local $sSectionData, $aSectionName, $iSectionName = 1 $aSectionName = StringRegExp($_HINI[$hIniFile][5], "\n(?is)\Q" & $sSectionName & "\E\r([^\n]+)", 3) If @Error Then If BitAND($iFlags, $INI_NOCREATE_REMOVE_DELETE) Then Return SetError(3, 0, "") $aIniFile[0] += 6 Redim $aIniFile[$aIniFile[0] + 1] $aIniFile[$aIniFile[0] - 5] = "[" $aIniFile[$aIniFile[0] - 4] = $sSectionName $aIniFile[$aIniFile[0] - 3] = "]" & @CRLF $_HINI[$hIniFile][4] += 1 $_HINI[$hIniFile][5] &= @LF & $sSectionName & @CR & ($aIniFile[0] - 4) $_HINI[$hIniFile][6] = $aIniFile[0] - 1 Else $_HINI[$hIniFile][6] = $aSectionName[0] + 3 $iSectionName = UBound($aSectionName) ;;If BitAND($iFlags, $INI_STRIPLEADTRAILING) = $INI_STRIPLEADTRAILING Then ;; BitOR($INI_STRIPLEADING, $INI_STRIPTRAILING) ;; $sSectionData = $aIniFile[$aSectionName[0] + 3] ;;ElseIf BitAND($iFlags, $INI_STRIPLEADING) Then ;; $sSectionData = $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4] ;;ElseIf BitAND($iFlags, $INI_STRIPTRAILING) Then ;; $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3] ;;Else ;; $sSectionData = $aIniFile[$aSectionName[0] + 2] & $aIniFile[$aSectionName[0] + 3] & $aIniFile[$aSectionName[0] + 4] ;;EndIf If Not BitAND($iFlags, $INI_NOOCCURRENCE) And $iSectionName > 1 Then $sSectionData = $aIniFile[$aSectionName[0] + 3] For $i = 1 To $iSectionName - 1 $sSectionData &= $aIniFile[$aSectionName[$i] + 3] If BitAND($iFlags, $INI_MERGE) Then For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4 $aIniFile[$y] = "" Next $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r' & $aSectionName[$i], "") EndIf Next If BitAND($iFlags, $INI_MERGE) Then $aIniFile[$aSectionName[0] + 3] = $sSectionData EndIf EndIf __IniSaveCache($hIniFile, $sSectionData, $sSectionName, $iFlags, $iSectionName, $aIniFile) Return $iSectionName ;SetError(Not $iSectionName, $iSectionName, $sSectionData) EndFunc ;==>__IniReadSectionEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniWriteSectionEx ; Description ...: Support Function for _IniWriteSectionEx ; Syntax.........: __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile) ; Parameters ....: See _IniWriteSectionEx() ; Return values .: See _IniWriteSectionEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniWriteSectionEx ; =============================================================================================================================== Func __IniWriteSectionEx(ByRef $hIniFile, ByRef $sSectionName, ByRef $aKeyValue, ByRef $iFlags, ByRef $scKeyName, ByRef $aIniFile) If BitAND($iFlags, $INI_REMOVE) Then Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3) If @Error Then Return SetError(3, 0, 0) $iaSectionName = UBound($aSectionName) - 1 If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0 For $i = 0 To $iaSectionName For $y = $aSectionName[$i] - 1 To $aSectionName[$i] + 4 $aIniFile[$y] = "" Next Next $_HINI[$hIniFile][4] -= $iaSectionName + 1 $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r[^\r\n]+', "", Int($iaSectionName = 0)) Return SetError(0, @Extended, 0) ElseIf BitAND($iFlags, $INI_RENAME) Then Local $iaSectionName, $aSectionName = StringRegExp($_HINI[$hIniFile][5], '\n(?is)\Q' & $sSectionName & '\E\r([^\n]+)', 3) If @Error Then Return SetError(3, 0, 0) $iaSectionName = UBound($aSectionName) - 1 If BitAND($iFlags, $INI_NOOCCURRENCE) Then $iaSectionName = 0 ;; $aKeyValue is New Section Name For $i = 0 To $iaSectionName $aIniFile[$aSectionName[$i]] = $aKeyValue Next $_HINI[$hIniFile][5] = StringRegExpReplace($_HINI[$hIniFile][5], '\n\K(?is)\Q' & $sSectionName & '\E(?=\r)', StringReplace(StringReplace($aKeyValue, "\", "\\", 0, 1), "\E", "\e", 0, 1), Int($iaSectionName = 0)) Return SetError(0, @Extended, 0) Else Local $iSN = $_HINI[$hIniFile][10] If BitAND($iFlags, $INI_OVERWRITEALL_APPENDDATA) Then If BitAND($iFlags, $INI_OVERWRITEALL) Then $aIniFile[$iSN] = "" If BitAND($iFlags, $INI_STRIPLEADING) Then $aIniFile[$iSN - 1] = "" If BitAND($iFlags, $INI_STRIPTRAILING) Then $aIniFile[$iSN + 1] = "" If IsArray($aKeyValue) Then For $i = 1 To $aKeyValue[0][0] $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF Next Else ;; KeyName\Value\Text Data will be writte exactly as in $aKeyValue (without Edit\Formatting ect ect) $aIniFile[$iSN] &= $aKeyValue & (StringRight($aKeyValue, 1) = @LF ? "" : @CRLF) EndIf Return SetError(0, 1, 0) Else Local $asKeyValue, $iKeyValue = 0, $sKNPattern, $iOffSet = StringInStr($aIniFile[$iSN], @LF, 1) For $i = 1 To $aKeyValue[0][0] $sKNPattern = '\n[\h\f\xb\x0]*(?i)(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*' If StringRegExp(StringLeft($aIniFile[$iSN], $iOffSet), '^(?i)[\h\f\xb\x0]*(?>\Q"' & $aKeyValue[$i][0] & '"\E|\Q' & $aKeyValue[$i][0] & '\E)[\h\f\xb\x0]*' & $scKeyName & '[\h\f\xb\x0]*[^\n]*') Then If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "") If BitAND($iFlags, $INI_DELETE) Then $aIniFile[$iSN] = StringTrimLeft($aIniFile[$iSN], $iOffSet) ElseIf Not BitAND($iFlags, $INI_NOOVERWRITE) Then $aIniFile[$iSN] = $aKeyValue[$i][2] & @CRLF & StringTrimLeft($aIniFile[$iSN], $iOffSet) EndIf ElseIf BitAND($iFlags, $INI_DELETE) Then $aIniFile[$iSN] = StringRegExpReplace($aIniFile[$iSN], $sKNPattern, "", (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? 1 : 0)) Else $asKeyValue = StringRegExp($aIniFile[$iSN], $sKNPattern, 1) $iOffSet = @Extended - 1 If Not @Error Then If BitAND($iFlags, $INI_NOOVERWRITE) Then If Not BitAND($iFlags, $INI_IGNOREDUPLICATE) Then $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet) & StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, "") Else $aIniFile[$iSN] = StringLeft($aIniFile[$iSN], $iOffSet + 1 - StringLen($asKeyValue[0])) & $aKeyValue[$i][2] & @CR & (BitAND($iFlags, $INI_IGNOREDUPLICATE) ? StringTrimLeft($aIniFile[$iSN], $iOffSet) : StringRegExpReplace(StringTrimLeft($aIniFile[$iSN], $iOffSet), $sKNPattern, "")) EndIf ElseIf Not BitAND($iFlags, $INI_REPLACEONLY) Then $aIniFile[$iSN] &= $aKeyValue[$i][2] & @CRLF Else $iKeyValue -= 1 EndIf EndIf $iKeyValue += 1 Next Return SetError(0, $iKeyValue, 0) EndIf EndIf EndFunc ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniFileWriteEx ; Description ...: Support Function for _IniFileWriteEx ; Syntax.........: __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile) ; Parameters ....: See _IniFileWriteEx() ; Return values .: See _IniFileWriteEx() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniFileWriteEx ; =============================================================================================================================== Func __IniFileWriteEx(ByRef $hIniFile, ByRef $iFlags, ByRef $sFilePath, ByRef $iFileEncoding, ByRef $aIniFile) Local $hFileOpen, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING), $iReadOnly = 0 $hFileOpen = FileOpen($sFilePath, $iFileEncoding) ; Check if file opened for writing OK If $hFileOpen = -1 Then If Not BitAND($iFlags, $INI_NOWRITEREADONLY) And StringInStr(FileGetAttrib($sFilePath), "R") Then FileSetAttrib($sFilePath, "-R") $iReadOnly = 1 $hFileOpen = FileOpen($sFilePath, $iFileEncoding) If $hFileOpen = -1 Then Return SetError(10, 0, 0) Else Return SetError(10, 0, 0) EndIf EndIf FileWrite($hFileOpen, ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5])) For $i = 6 To $aIniFile[0] Step 6 FileWrite($hFileOpen, $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5])) Next FileClose($hFileOpen) If $iReadOnly Then FileSetAttrib($sFilePath, "+R") Return 0 EndFunc ;==>__IniFileWriteEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniGetFileStringData ; Description ...: Support Function for _IniGetFileStringData ; Syntax.........: __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile) ; Parameters ....: See _IniGetFileStringData() ; Return values .: See _IniGetFileStringData() ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is used internally by _IniGetFileStringData ; =============================================================================================================================== Func __IniGetFileStringData(ByRef $hIniFile, ByRef $iFlags, ByRef $aIniFile) Local $sData, $iSL = BitAND($iFlags, $INI_STRIPLEADING), $iST = BitAND($iFlags, $INI_STRIPTRAILING) Local $sData = ($iSL ? "" : $aIniFile[3]) & $aIniFile[4] & ($iST ? "" : $aIniFile[5]) For $i = 6 To $aIniFile[0] Step 6 $sData &= $aIniFile[$i] & $aIniFile[$i + 1] & $aIniFile[$i + 2] & ($iSL ? "" : $aIniFile[$i + 3]) & $aIniFile[$i + 4] & ($iST ? "" : $aIniFile[$i + 5]) Next Return $sData EndFunc ;==>__IniGetFileStringData ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __IniSaveCache ; Description ...: Save in Cache last Read Section ; Syntax.........: __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile) ; Parameters ....: $hIniFile - Handle to the INI file to query "see _IniOpenFileEx()" ; $sSectionData - Section Strings text/data ; $sSectionName - Section Name ; $iFlags - Section Flags ; $iSectionName - Number of SectionName in INI File ; $aIniFile - Array of INI File ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: This function is Internal Only ; =============================================================================================================================== Func __IniSaveCache(ByRef $hIniFile, ByRef $sSectionData, ByRef $sSectionName, ByRef $iFlags, ByRef $iSectionName, ByRef $aIniFile) $_HINI[$hIniFile][7] = $sSectionName $_HINI[$hIniFile][8] = (BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) = $INI_MERGE) ? 1 : $iSectionName $_HINI[$hIniFile][9] = $iFlags If $iSectionName > 1 And Not BitAND($iFlags, $INI_MERGE_NOOCCURRENCE) Then $aIniFile[1] = $sSectionData $_HINI[$hIniFile][10] = 1 Else $aIniFile[1] = "" $_HINI[$hIniFile][10] = $_HINI[$hIniFile][6] EndIf Return 0 EndFunc ;==>__IniSaveCache ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSeparatorCharacter ; Description ...: Get Separator Character (non present character) ; Syntax.........: __GetSeparatorCharacter(ByRef $sData) ; Parameters ....: $sData - INI String\Text Data ; Return values .: None ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __GetSeparatorCharacter(ByRef $sData) If Not StringInStr($sData, ChrW(8232), 1) Then Return ChrW(8232) If Not StringInStr($sData, ChrW(8233), 1) Then Return ChrW(8233) For $i = 1 To 31 If $i > 8 And $i < 14 Then ContinueLoop If Not StringInStr($sData, Chr($i), 1) Then Return Chr($i) Next $sData = StringRegExpReplace($sData, '\r\n?', @LF) Return @CR EndFunc ;==>__GetSeparatorCharacter example #include <IniEx.au3> #include <Array.au3> Local $sData = @CRLF, $aData, $iData, $iTimerDiff, $hIniFile FileDelete(@DesktopDir & "\Test.ini") For $i = 1 To 10 $sData &= "[SectionName_" & $i & "]" & @CRLF For $y = 1 to 100000 $sData &= "KeyName" & $y & " = Value" & $y & @CRLF Next Next FileWrite(@DesktopDir & "\Test.ini", $sData) ;25 MB - 1.000.000 Line, Key-Value $sData = "" $iTimerDiff = TimerInit() ;;_IniOpenFileEx() $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("_IniOpenFileEx TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniGetSectionNumberEx() $iData = _IniGetSectionNumberEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniGetSectionNumberEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite("SectionNumber - " & $iData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniRenameSectionEx() _IniRenameSectionEx($hIniFile, "SectionName_10", "SectionName_111") If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniRenameSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadSectionNamesEx() $aData = _IniReadSectionNamesEx($hIniFile) If @Error Then ConsoleWrite("Error - " & @Error & @LF) Exit EndIf $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionNamesEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $sData = _IniReadSectionEx($hIniFile, "SectionName_8") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ;;ConsoleWrite($sData & @LF & @LF) ;;MsgBox(0, "SectionName_8", $sData) $iTimerDiff = TimerInit() ;;_IniReadSectionEx() $aData = _IniReadSectionEx($hIniFile, "SectionName_8", $INI_2DARRAYFIELD) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_2DARRAYFIELD $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) _ArrayDisplay($aData, "IniReadSectionEx") $iTimerDiff = TimerInit() ;;_IniReadEx() $sData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99980") $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff& @LF) ConsoleWrite($sData & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() $aData = _IniReadEx($hIniFile, "SectionName_8", "KeyName99988", "Default Return", $INI_ARRAYDATA) ;$INI_NOOCCURRENCE + $INI_MERGE + $INI_ARRAYDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) ConsoleWrite($aData[1] & @LF & @LF) _ArrayDisplay($aData, "IniReadEx") $iTimerDiff = TimerInit() ;;_IniDeleteEx() _IniDeleteEx($hIniFile, "SectionName_8", "KeyName99988") ;$INI_IGNOREDUPLICATE + $INI_NOOCCURRENCE + $INI_REMOVE $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniDeleteEx TimerDiff - " & $iTimerDiff & @LF & @LF) $iTimerDiff = TimerInit() ;;_IniWriteSectionEx() _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX = ValueX") ; $INI_NOOCCURRENCE + $INI_IGNOREDUPLICATE + $INI_MERGE + $INI_REMOVE + $INI_OVERWRITEALL + $INI_APPENDDATA $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWriteSectionEx TimerDiff - " & $iTimerDiff & @LF & @LF) ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX") & @LF) $iTimerDiff = TimerInit() For $i = 1 To 5 _IniWriteSectionEx($hIniFile, "SectionName_8", "KeyNameX" & $i & " = ValueX" & $i) Next For $i = 6 To 10 _IniWriteEx($hIniFile, "SectionName_8", "KeyNameX" & $i, "ValueX" & $i) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniWrite*Ex TimerDiff - " & $iTimerDiff & @LF) $iTimerDiff = TimerInit() ;;_IniReadEx() For $i = 1 To 10 ConsoleWrite(_IniReadEx($hIniFile, "SectionName_8", "KeyNameX" & $i) & @LF) Next $iTimerDiff = TimerDiff($iTimerDiff) ConsoleWrite("IniReadEx TimerDiff - " & $iTimerDiff & @LF) _IniCloseFileEx($hIniFile) Exit ;~ >Running:(3.3.11.3):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script.au3" ;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop ;~ _IniOpenFileEx TimerDiff - 2656.48548057389 ;~ IniGetSectionNumberEx TimerDiff - 0.0343594296492653 ;~ SectionNumber - 10 ;~ ;~ IniRenameSectionEx TimerDiff - 0.204971769976651 ;~ ;~ IniReadSectionNamesEx TimerDiff - 0.0584505240010489 ;~ ;~ IniReadSectionEx TimerDiff - 6.80316707055452 ;~ ;~ IniReadSectionEx TimerDiff - 1831.04639075913 ;~ ;~ IniReadEx TimerDiff - 24.1380917325683 ;~ Value99980 ;~ ;~ IniReadEx TimerDiff - 111.67841469541 ;~ Value99988 ;~ ;~ IniDeleteEx TimerDiff - 43.9488700091941 ;~ ;~ IniWriteSectionEx TimerDiff - 28.2560891228314 ;~ ;~ ValueX ;~ IniWrite*Ex TimerDiff - 261.353224415258 ;~ ValueX1 ;~ ValueX2 ;~ ValueX3 ;~ ValueX4 ;~ ValueX5 ;~ ValueX6 ;~ ValueX7 ;~ ValueX8 ;~ ValueX9 ;~ ValueX10 ;~ IniReadEx TimerDiff - 261.622965684803 ;~ +>00:07:21 AutoIt3.exe ended.rc:0 ;~ >Exit code: 0 Time: 5.914 ; $INI_OPEN_FILEQUEUE (268435456) - Open INI file from Memory\Variable, $sFilePath must contain String Text Data of INI file $hIniFile = _IniOpenFileEx(@DesktopDir & "\Test.ini") ;ect ect ect ;or $hIniFile = _IniOpenFileEx($sData, $INI_OPEN_FILEQUEUE) ;ect ect ect ;Or direct mode, without load ini or using handles ; $sSectionName - The name of the section containing the Key\Value, This parameter can be NULL (use the $NULL_REF to set NULL this parameter) ; If $sSectionName is NULL, $hIniFile must be contain Section String\Key\Value\Data ;; _IniDeleteEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadEx($hIniFile, $sSectionName, $sKeyName) _IniDeleteEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniReadSectionEx($hIniFile, $sSectionName, $sKeyName) _IniReadSectionEx($sData, $NULL_REF, $sKeyName) ;$NULL_REF = NULL ;; _IniWriteEx($hIniFile, $sSectionName, $sKeyName, $sValue) _IniWriteEx($sData, $NULL_REF, $sKeyName, $sValue) ;$NULL_REF = NULL ;;ect ect ect So for all other functions IniEx.au3
  25. How to get the thrid number of a file version. Example: Let's say I have a file with below properties. I want only the third number like here it is 1941 as highlighted. Is there any built in function to get it??
×
×
  • Create New...