ajetrumpet
Banned
- Local time
- Today, 12:40
- Joined
- Jun 22, 2007
- Messages
- 5,638
The attached example shows how you can get data into and out of a text file by using the File System Object and variations of the Read/Write methods.
This is probably the most common method used, as it writes in append mode, and not in write mode, and it also reads an entire file instead of only the first line...
3/6/2010
I will post some streaming examples once in a while here. Most of it will be code that I use or have used.
Code to create a (comma) delimited text file spreadsheet of all files in a windows folder:
I just ran into a text file that had no definite delimiter and it wasn't fixed width either (don't ask me where I got it). Interesting format:
My fix-it solution to make it importable into Access:
This is probably the most common method used, as it writes in append mode, and not in write mode, and it also reads an entire file instead of only the first line...
3/6/2010
I will post some streaming examples once in a while here. Most of it will be code that I use or have used.
Code to create a (comma) delimited text file spreadsheet of all files in a windows folder:
PHP:
Dim fs, f, f1, fc, s, oFile, folderspec
folderspec = "FOLDER ADDRESS"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
s = s & Left(f1.Name, (Len(f1.Name) - 4)) & "," & Round(f1.Size / 1048576, 0) & "mb"
s = s & vbCrLf
Next
Set oFile = fs.createtextfile("COMPLETE ADDRESS OF NEW TEXT FILE", True)
oFile.writeline s
oFile.Close
Set f = Nothing
Set fc = Nothing
Set fs = Nothing
Set oFile = Nothing
I just ran into a text file that had no definite delimiter and it wasn't fixed width either (don't ask me where I got it). Interesting format:
My fix-it solution to make it importable into Access:
PHP:
Dim fs, s, oFile, strpart, strsplit, retstring
Set fs = CreateObject("Scripting.FileSystemObject")
Set oFile = fs.opentextfile("FILE'S PATH", 1, False)
s = oFile.read(111111111)
oFile.Close
For Each strpart In Split(s, vbCrLf)
If InStr(strpart, "-----") = 0 Then
For Each strsplit In Split(strpart, "|")
retstring = retstring & Trim(strsplit) & ","
Next strsplit
retstring = Trim( _
Right( _
Replace( _
retstring, ",,", ""), _
(Len(retstring) - 1))) & vbCrLf
End If
Next strpart
Set oFile = fs.createtextfile("FILE'S PATH", True)
oFile.writeline retstring
oFile.Close
Set fs = Nothing
Set oFile = Nothing
Attachments
Last edited: