Je reçois une erreur lorsque j'utilise opentextfile. Le problème est bizarre car cela fonctionne pour quelques centaines de fichiers puis apparaît.OpentextFile Autorisation refusée Erreur
Fondamentalement, le script obtient une collection de fichiers, recherche dans ceux-ci une chaîne qu'il supprime ensuite et réécrit le contenu modifié dans le même fichier. Le problème se produit lorsque le script veut à nouveau ouvrir le fichier afin qu'il puisse y écrire le contenu modifié.
Voici le code:
For Each objFile in colFiles
Set objCurrentFile = objFSO.OpenTextFile(objFile.Path, ForReading)
'Get file contents - exclude end tag '
Do Until objCurrentFile.AtEndOfStream
strLine = objCurrentFile.ReadLine
If InStr(strLine, strSearchTerm) = 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objCurrentFile.Close
objCurrentFile = nothing
'Write new file contents to existing file '
Set objNewFile = objFSO.OpenTextFile(objFile.Path, ForWriting) 'PROBLEM LINE '
objNewFile.Write strNewContents
objNewFile.Close
objNewFile = nothing
Next
Quelle est l'erreur que vous obtenez? – aphoria