Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
  On 3/30/2017 at 12:21 PM, JLogan3o13 said:

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

Expand  

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
Posted

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:

  Reveal hidden contents

 

Posted (edited)

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
Posted

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.

  Reveal hidden contents

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

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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?

  • Moderators
Posted (edited)

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:

  Reveal hidden contents

 

Posted
#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.

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
×
×
  • Create New...