Si encuentras algo que no comprendes puedes comentarlo y haremos todo lo posible de ayudarte lo mas rápido que podamos.
Solución:
Quizás esto aclare las cosas. (O confundirte más,)
Const ForReading = 1
Const ForWriting = 2
sFolder = "H:Letter DisplayLetters"
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oFile In oFSO.GetFolder(sFolder).Files
If UCase(oFSO.GetExtensionName(oFile.Name)) = "LTR" Then
ProcessFiles oFSO, oFile
End if
Next
Set oFSO = Nothing
Sub ProcessFiles(FSO, File)
Set oFile2 = FSO.OpenTextFile(File.path, ForReading)
str1000 = "1000"
str1100 = "1100"
str1200 = "1200"
str9990 = "9990"
arrCommas1 = Array(14,31,41,59,70,81,101,111,124,138)
arrCommas2 = Array(14,31,41,55,79,144,209,274,409,563,589,608,623)
arrCommas3 = ArraY (14,32,41,73,83,97,106,156,167,184,188,195,207,260,273,332,368,431,461,472,593,617,666,772,810,834,848,894,898)
arrCommas4 = Array(14,31,41)
Do Until oFile2.AtEndOfStream
strLine = oFile2.ReadLine
If Left(strLine, 4) = str1000 then
intLength = Len(strLine)
For Each strComma in arrCommas1
strLine = Left(strLine, strComma - 1) + "," _
+ Mid(strLine, strComma, intLength)
Next
End If
If Left(strLine, 4) = str1100 then
intLength = Len(strLine)
For Each strComma in arrCommas2
strLine = Left(strLine, strComma - 1) + "," _
+ Mid(strLine, strComma, intLength)
Next
End If
If Left(strLine, 4) = str1200 then
intLength = Len(strLine)
For Each strComma in arrCommas3
strLine = Left(strLine, strComma - 1) + "," _
+ Mid(strLine, strComma, intLength)
Next
End If
If Left(strLine, 4) = str9990 then
intLength = Len(strLine)
For Each strComma in arrCommas4
strLine = Left(strLine, strComma - 1) + "," _
+ Mid(strLine, strComma, intLength)
Next
End If
strText = strText & strLine & vbCrLf
Loop
sFile = File.path
oFile2.close
set oFile2 = Nothing
Set File = FSO.OpenTextFile(sFile , ForWriting)
File.Write strText
File.Close
Set File = Nothing
end sub
Su secuencia de comandos actual básicamente hace lo siguiente:
Set objFile = objFSO.OpenTextFile("...", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
'do stuff with strLine and append to strText
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("...", ForWriting)
objFile.Write strText
objFile.Close
Para procesar todos los archivos en una carpeta determinada, solo necesita agregar un bucle externo alrededor de eso y ajustar algunas instrucciones en consecuencia:
For Each f In objFSO.GetFolder("C:somefolder").Files
Set objFile = f.OpenAsTextStream
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
'do stuff with strLine and append to strText
Loop
objFile.Close
Set objFile = f.OpenAsTextStream(ForWriting)
objFile.Write strText
objFile.Close
Next
Si entiendes que te ha sido provechoso nuestro post, nos gustaría que lo compartas con el resto programadores de esta forma nos ayudas a difundir nuestra información.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)