Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y aura
nouvelle section avec le nom corriger.
merci de votre aide
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y aura
nouvelle section avec le nom corriger.
merci de votre aide
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y aura
nouvelle section avec le nom corriger.
merci de votre aide
Call ReplaceInFile("c:ini.ini", "SECTION2", "MA NOUVELLE
SECTION") End Sub
Call ReplaceInFile("c:ini.ini", "SECTION2", "MA NOUVELLE
SECTION") End Sub
Call ReplaceInFile("c:ini.ini", "SECTION2", "MA NOUVELLE
SECTION") End Sub
[SECTION2]
[SECTION23]
[SECTION2]
[SECTION23]
[SECTION2]
[SECTION23]
il suffirait de rechercher "[SECTION2]" et remplacer par "[quelque
chose...]" et on serait certain de l'unicité de la modification, non ?
il suffirait de rechercher "[SECTION2]" et remplacer par "[quelque
chose...]" et on serait certain de l'unicité de la modification, non ?
il suffirait de rechercher "[SECTION2]" et remplacer par "[quelque
chose...]" et on serait certain de l'unicité de la modification, non ?
MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit d'un
parcours du tableau et comparaison de chaque entrée avec [section]
MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit d'un
parcours du tableau et comparaison de chaque entrée avec [section]
MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit d'un
parcours du tableau et comparaison de chaque entrée avec [section]
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
merci de votre aide
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
merci de votre aide
Bonjour a tous,
Je voudrais savoir qu'elle est la meilleure façon d'éditer par le
code le nom d'une section d'un fichier.ini. Si on utilise les api pour
gérer les fichiers ini et que l'on édite le nom de la section il y
aura une nouvelle section avec le nom corriger.
merci de votre aide
naaa.. mon cerveau n'a pas lu ça :MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection > sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <> "]")
Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection, sNewSection)
Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
naaa.. mon cerveau n'a pas lu ça :
MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection > sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <> "]")
Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection, sNewSection)
Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
naaa.. mon cerveau n'a pas lu ça :MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection > sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <> "]")
Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection, sNewSection)
Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
"Zoury" wrote in
news::naaa.. mon cerveau n'a pas lu ça :MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection >> sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <>
"]") Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection,
sNewSection) Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
Merci a tous de vos réponses. Est-ce que lire la section, la placer
dans un tableau, supprimer la section, recréé une section et
ré-écrire les clés est une façon propre.
Merci Raymond Fournier.
"Zoury" <yanick_lefebvre@hotmail.com> wrote in
news:e756sQFaEHA.3404@TK2MSFTNGP11.phx.gbl:
naaa.. mon cerveau n'a pas lu ça :
MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection >> sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <>
"]") Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection,
sNewSection) Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
Merci a tous de vos réponses. Est-ce que lire la section, la placer
dans un tableau, supprimer la section, recréé une section et
ré-écrire les clés est une façon propre.
Merci Raymond Fournier.
"Zoury" wrote in
news::naaa.. mon cerveau n'a pas lu ça :MYKEY=[SECTION2]
Celà revient à splitter le fichier - split(contenu, vbcrlf) - suivit
d'un parcours du tableau et comparaison de chaque entrée avec
[section]
dans ce cas autant utiliser CFile... :O)
fichier ini.ini :
[SECTION1]
KEY=[SECTION2]
[SECTION2]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
code
'***
' Module1
Option Explicit
Private Sub Main()
Call RenameINISection("c:ini.ini", "SECTION2", "MY_NEW_SECTION")
End Sub
Private Sub RenameINISection(ByRef sFilePath As String, ByRef
sOldSection As String, ByRef sNewSection As String)
Dim f As CFile
Dim i As Long
Dim lLen As Long
If (Not FileExists(sFilePath)) Then
Call Err.Raise(53) ' File not found
Exit Sub
End If
If (Left$(sOldSection, 1) <> "[") Then sOldSection = "[" &
sOldSection If (Right$(sOldSection, 1) <> "]") Then sOldSection >> sOldSection & "]" If (Left$(sNewSection, 1) <> "[") Then
sNewSection = "[" & sNewSection If (Right$(sNewSection, 1) <>
"]") Then sNewSection = sNewSection & "]"
Set f = New CFile
lLen = Len(sOldSection)
Call f.OpenFile(sFilePath)
For i = 1 To f.LineCount
If (Left$(f.Lines(i), Len(sOldSection)) = sOldSection) Then
f.Lines(i) = Replace(f.Lines(i), sOldSection,
sNewSection) Call f.SaveFile
Exit For
End If
Next i
End Sub
Private Function FileExists(ByRef sFilePath As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(sFilePath) And vbDirectory) = 0
End Function
'***
au final :
[SECTION1]
KEY=[SECTION2]
[MY_NEW_SECTION]
KEY=MA_VALEUR
[SECTION3]
KEY=[SECTION2]
Merci a tous de vos réponses. Est-ce que lire la section, la placer
dans un tableau, supprimer la section, recréé une section et
ré-écrire les clés est une façon propre.
Merci Raymond Fournier.
Kill IniFile
Kill IniFile
Kill IniFile