Jump to content

IniReadSectionNames problem? [SOLVED]


 Share

Recommended Posts

The path are cutted! maybe double [] in the path generated the error.

Example:
 

[I:\aaa\cc\aa vv vv vv (dd).txt]
name=aa vv vv vv (dd).txt
[I:\ffff\ffff\ffff ffff ffff ffff  [ffff]\ffff\ffff.txt]
name=ffff.txt

$ini = IniReadSectionNames(@ScriptDir&"\my.ini")
_ArrayDisplay($ini)
for $x = 1 to UBound($ini)-1
ConsoleWrite($ini[$x]&@CRLF)
Next

 

Edited by rootx
Amended title
Link to comment
Share on other sites

  • Moderators

@rootx if you believe you have found a bug, please use the Bug Tracker section to report it.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

11 minutes ago, JLogan3o13 said:

@rootx if you believe you have found a bug, please use the Bug Tracker section to report it.

I'm not sure why [] is the standard ... and the solution is to skip the brackets inside the path string. But I'm not sure if you can, or you need to clean the name of the folder or change approach.

 

Edited by rootx
Link to comment
Share on other sites

Are you sure that square brackets are allowed in a section name?
Do INI-files support escape characters or encoded characters?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

for example it can happen that people write of the strange path as C: \ name [IBIS 001] 2017. But ini standard are

[C: \ name [IBIS 001] 2017\file.txt]

name=IBIS 001

years=2017

etc...

 

Edited by rootx
Link to comment
Share on other sites

Just over a month ago, I created a viewer (ASCII Checker) to help with determining INI entry issues.

It might be of some help to you, and can be found here.

There is also a link in the quoted section, to a Wikipedia article about INI files and escape characters.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • Moderators

rootx,

You will have to do some pre/post-processing of the section names if you think there might be [ ] characters in the section name:

#include <Array.au3>

$sIniFile = "Test.ini"

$sPath = "C: \ name [IBIS 001] 2017\file.txt"

$sEscPath = StringReplace(StringReplace($sPath, "[", "\5B"), "]", "\5D")

IniWrite($sIniFile, $sEscPath, "Key", "Value")

$aSections = IniReadSectionNames($sIniFile)

For $i = 1 To $aSections[0]
    $aSections[$i]  = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]")
Next

_ArrayDisplay($aSections, "", Default, 8)

And please do not be so quick to declare a bug - best ask first next time.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thx, But the question is... if you have this ini file you are not able to read this file.

[C: \ name [5BIBIS 001] 5D 2017\file.txt]
Key=Value

#include <Array.au3>

$sIniFile = "Test.ini"

$aSections = IniReadSectionNames($sIniFile)

For $i = 1 To $aSections[0]
    $aSections[$i]  = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]")
    ConsoleWrite($aSections[$i])
Next

_ArrayDisplay($aSections, "", Default, 8)

And how can you open this file C: \ name [5BIBIS 001 with iniread?

Link to comment
Share on other sites

  • Moderators

rootx,

You will need to read the ini file into an array, preprocess the [ & ] characters which are not bounding the section and then rewrite it - something like this:

#include <Array.au3>
#include <File.au3>

$sPath = "C: \ name [IBIS 001] 2017\file.txt"

$sIniFile = "Test.ini"

$hFile = FileOpen($sIniFile, $FO_OVERWRITE)
FileWrite($hFile, "[" & $sPath & "]" & @CRLF & "Key=Value")
FileClose($hFile)

Global $aLines
_FileReadToArray($sIniFile, $aLines)

_ArrayDisplay($aLines, "Original ini content", Default, 8)

For $i = 1 To $aLines[0]
    ; Look for the section names
    If StringLeft($aLines[$i], 1) = "[" Then
        ; Extract the sectionname from within the [ & ]
        $sSectionName = StringTrimLeft(StringtrimRight($aLines[$i], 1), 1)
        ; Escape any [ & ] and rewrit ewith the external [ & ]
        $aLines[$i] = "[" & StringReplace(StringReplace($sSectionName, "[", "\5B"), "]", "\5D") & "]"
    EndIf
Next
; Now rewrite the escaped ini file
_FileWriteFromArray($sIniFile, $aLines, 1)

; Now read it
$aSections = IniReadSectionNames($sIniFile)

For $i = 1 To $aSections[0]
    $aSections[$i]  = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]")
Next

_ArrayDisplay($aSections, "Section names from ini", Default, 8)

M23

Edited by Melba23
Typos

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#include <Array.au3>
#include <File.au3>
$sIniFile = "Test.ini"

DirCreate(@ScriptDir&"\name [5BIBIS 001] 5D 2017")
FileWrite(@ScriptDir&"\name [5BIBIS 001] 5D 2017\file.txt","xxxx")


$file = _FileListToArrayRec(@ScriptDir,"*.txt",1,1,1,2)


For $s = 1 to UBound($file)-1
    IniWrite($sIniFile, $file[$s],"name",StringRegExpReplace($file[$s], "^.*\\(.*)$", "$1"))
Next

$aSections = IniReadSectionNames($sIniFile)

For $i = 1 To $aSections[0]
    $aSections[$i]  = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]")
    ConsoleWrite("WRONG "&$aSections[$i] & "  WRONG " & $aSections[$i]&@CRLF)
Next

_ArrayDisplay($aSections, "", Default, 8)

Thx, but at the same time i have writted!! I try your script thx again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...