Open as Input Comma Problem Extract Txt File

  • Thread starter Thread starter rebelscum0000
  • Start date Start date
R

rebelscum0000

Dear All,

Several days worrking in this code and still do not work

I have a .CRC File that I can read with the notepad

Is a large file and I want to extract severals strings, the data
contained in this file is somothing like

DIR mdb progress\Duplicates 2007\
fbf4d7d1e018ea6dca2c2c4c34d13a1a Duplicates 01-02-07.mdb
ab7af7d99401341333433097b4cc69e4 Duplicates 01-03-07.mdb
7238cb2af00429ea1aab5eb4456c0884 DuplicatesII 01-06-07.mdb
9a8d5f26de626592e6a2c3c647f43175 DuplicatesII 01-07-07.mdb
81b6b2241500b9603fae05f002ac8bb5 DuplicatesII 03-03-07 .mdb
8a8c345acbe220d88ce59f7b72a99c81 DuplicatesII 03-04-07 .mdb
5cb79b098b4317f98d11aafcd62a6203 DuplicatesII 03-05-07 .mdb
367ef3abcacea66f5e698370c501d5cf DuplicatesII 03-06-07 .mdb
548767e7ca2b29c5ae6e5f022fafe0b6 DuplicatesII 03-07-07 .mdb
DIR mdbs\Access Web\November 6, 2000\
3888a0956f14cdc8d8cf056d297e3455 accwebfaq-10-10-00-A9.zip
f80551a682b0b6fbf27a51e688ec4f3b accwebfaq-10-10-00-A9.zip.log
49480b46baa56c800b6cfc7310b626d8 Downloads.txt
DIR mdbs\Access Web\November 6, 2000\accwebfaq-10-10-00-A9\
45e1f4a0bf8859f02536c68fe5d91834 AccWebFaqv9.mdb
baba4c637b9add8126672efda2ab28ac Cursor1.cur
0c7b167c235a7cd43ab760bc5bc854e3 Done.wav
fb45431715e37c47a5cae5dc37e8039e Start.wav
DIR mdbs\ACG Soft\Browse Dialogs\
c10ee53f4c317b6427711fb31ca3ba6f Osdlg.hlp
5c93acbc517e311bf7f7173c3b782425 osdlg9.mdb
DIR mdbs\ACG Soft\Browse Dialogs\Info_Browse Dialogs\
3b5d15fd0e0c06034a88be788bbf4454 Desktop.ini
157da4f0fa6474685ccece81df882b9d Readme_Browse Dialogs.txt
DIR mdbs\ACG Soft\Browse Dialogs\Zip_Browse Dialogs\
64bbc4f96ce6aa60ed1e2a563bf0af6f Downloads.txt
46d8b8dcb871d5e066f5ac697b0c6424 osdlg9.zip
65b3826b743db221a75ec010178d083b osdlg9.zip.log

First I did extract all the strings that begins with DIR

I am opening a recordset and using .addnew and .update functions.
This all works fine until the string has a comma like

DIR mdbs\Access Web\November 6, 2000\accwebfaq-10-10-00-A9\



In the Tb appears only DIR mdbs\Access Web\November 6

I read somewhere "If my data is in comma seperated like
John, Smith, "123 Adddress", format then input # is all i need"

I guess this is my problem but I do not have any idea how to fix it
If I open the the file as Binary my database crash

Please help me!

My question is how to read the entire string no matter if if has a
commas or any strange character, or what options do I still have
perhaps FSO?

Thanks in advance
Regards,
Antonio Macias

This is my code


Sub OpenWinBrowse()

Dim MyDlg As New DialogClass 'Common Dialogs Class Module for Access
and VBA
Dim GetFolder As String
Dim LenGetFolder As Integer
Dim MidPathGetFolder As String
Dim strDrive As String
Dim strDir As String
Dim SearchChar As String
Dim MyCounterDir As Integer
Dim intFF As Integer
Dim i As Integer
Dim MyDirPos As Integer
Dim LenDir As Integer
Dim MySearchDirMid As String
Dim MyDir As String
Dim MyDirRev As Integer
Dim MyDirLeft As String
Dim MyDirTrim As String
Dim MyDirResult1 As String
Dim MyDirResult2 As String
Dim MyDirResult3 As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sQL16 As String


'On Error GoTo ErrorHandling

'Opens the Browse Dialog
With MyDlg
.TypeFile = 0 'All file Types
.TypeFile = 4 'Text Files
.DialogType = "Browse"
End With

'Show the select type of dialog selected with the properties
desired
MyDlg.Show

'The name for the chosen file or directory
'<Drive>:\Folder
GetFolder = MyDlg.ReturnFilePath
LenGetFolder = Len(GetFolder)
MidPathGetFolder = Mid(GetFolder, 4, LenGetFolder)
'<Drive>
strDrive = Left(GetFolder, 1)

'Initialize Variables
strDir = GetFolder & "\" & MidPathGetFolder & ".CRC"
SearchChar = "DIR"
MyCounterDir = 0
intFF = FreeFile
Open strDir For Input As #intFF

For i = 1 To 7 'Discard the first seven lines of the file
Line Input #intFF, ReadText
Next i

Do While Not EOF(intFF)
Input #intFF, ReadText
MyDirPos = InStr(1, ReadText, SearchChar, 1)

If MyDirPos = 1 Then
LenDir = Len(ReadText)
'DIR Folder\Folder\...
MySearchDirMid = Mid(ReadText, 1, LenDir)
MyDirResult1 = Trim(MySearchDirMid)
'Folder\
MyDir = Mid(ReadText, 4, LenDir)
MyDirResult2 = Trim(MyDir)
MyDirRev = InStrRev(MyDirResult2, "\", -1, vbTextCompare)
'Folder\Folder\...
MyDirLeft = Left(MyDir, MyDirRev)
MyDirTrim = Trim(MyDirLeft)
MyDirResult3 = GetFolder & "\" & MyDirTrim

MyCounterDir = MyCounterDir + 1

'Initialize Variables
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("Directories_" & strDrive &
"_Tbl", dbOpenDynaset)

With rs
.AddNew 'Add a new record
!ID = MyCounterDir
!SearchDir = MyDirResult1
!MyDirectories = MyDirResult2
!MyDirectoryPath = MyDirResult3
.Update 'Write the new record to the table
.Bookmark = .LastModified
End With

End If
Loop

Close #intFF
rs.Close
db.Close
Set db = Nothing

'This Query UPDATES Dir and C:\Dups V.1.0 WHERE the CRC File
contains "DIR" AND C:\Dups V.1.0\
'AND the File Name IS empty
sQL16 = _
"UPDATE Directories_" & strDrive & "_Tbl SET " & _
"MyDirectories = 'DIR', " & _
"MyDirectoryPath = 'C:\Dups V.1.0' " & _
"WHERE ((MyDirectories ='" & "" & "' ) " & _
"AND (MyDirectoryPath='C:\Dups V.1.0\'));"

CurrentDb.Execute sQL16, dbFailOnError

End Sub
 
You have your open as input with a pound in front of the intff. That
will not read special characters. Get rid of the # on your open
statement.

Bart
 
If you want to read the entire line, use
Line Input #
not
Input #

Dear All,
Several days worrking in this code and still do not work
I have a .CRC File that I can read with the notepad
Is a large file and I want to extract severals strings, the data
contained in this file is somothing like
DIR mdb progress\Duplicates 2007\
fbf4d7d1e018ea6dca2c2c4c34d13a1a Duplicates 01-02-07.mdb
ab7af7d99401341333433097b4cc69e4 Duplicates 01-03-07.mdb
7238cb2af00429ea1aab5eb4456c0884 DuplicatesII 01-06-07.mdb
9a8d5f26de626592e6a2c3c647f43175 DuplicatesII 01-07-07.mdb
81b6b2241500b9603fae05f002ac8bb5 DuplicatesII 03-03-07 .mdb
8a8c345acbe220d88ce59f7b72a99c81 DuplicatesII 03-04-07 .mdb
5cb79b098b4317f98d11aafcd62a6203 DuplicatesII 03-05-07 .mdb
367ef3abcacea66f5e698370c501d5cf DuplicatesII 03-06-07 .mdb
548767e7ca2b29c5ae6e5f022fafe0b6 DuplicatesII 03-07-07 .mdb
DIR mdbs\Access Web\November 6, 2000\
3888a0956f14cdc8d8cf056d297e3455 accwebfaq-10-10-00-A9.zip
f80551a682b0b6fbf27a51e688ec4f3b accwebfaq-10-10-00-A9.zip.log
49480b46baa56c800b6cfc7310b626d8 Downloads.txt
DIR mdbs\Access Web\November 6, 2000\accwebfaq-10-10-00-A9\
45e1f4a0bf8859f02536c68fe5d91834 AccWebFaqv9.mdb
baba4c637b9add8126672efda2ab28ac Cursor1.cur
0c7b167c235a7cd43ab760bc5bc854e3 Done.wav
fb45431715e37c47a5cae5dc37e8039e Start.wav
DIR mdbs\ACG Soft\Browse Dialogs\
c10ee53f4c317b6427711fb31ca3ba6f Osdlg.hlp
5c93acbc517e311bf7f7173c3b782425 osdlg9.mdb
DIR mdbs\ACG Soft\Browse Dialogs\Info_Browse Dialogs\
3b5d15fd0e0c06034a88be788bbf4454 Desktop.ini
157da4f0fa6474685ccece81df882b9d Readme_Browse Dialogs.txt
DIR mdbs\ACG Soft\Browse Dialogs\Zip_Browse Dialogs\
64bbc4f96ce6aa60ed1e2a563bf0af6f Downloads.txt
46d8b8dcb871d5e066f5ac697b0c6424 osdlg9.zip
65b3826b743db221a75ec010178d083b osdlg9.zip.log
First I did extract all the strings that begins with DIR
I am opening a recordset and using .addnew and .update functions.
This all works fine until the string has a comma like
DIR mdbs\Access Web\November 6, 2000\accwebfaq-10-10-00-A9\
In the Tb appears only DIR mdbs\Access Web\November 6
I read somewhere "If my data is in comma seperated like
John, Smith, "123 Adddress", format then input # is all i need"
I guess this is my problem but I do not have any idea how to fix it
If I open the the file as Binary my database crash
Please help me!
My question is how to read the entire string no matter if if has a
commas or any strange character, or what options do I still have
perhaps FSO?
Thanks in advance
Regards,
Antonio Macias
This is my code
Sub OpenWinBrowse()
Dim MyDlg As New DialogClass 'Common Dialogs Class Module for Access
and VBA
Dim GetFolder As String
Dim LenGetFolder As Integer
Dim MidPathGetFolder As String
Dim strDrive As String
Dim strDir As String
Dim SearchChar As String
Dim MyCounterDir As Integer
Dim intFF As Integer
Dim i As Integer
Dim MyDirPos As Integer
Dim LenDir As Integer
Dim MySearchDirMid As String
Dim MyDir As String
Dim MyDirRev As Integer
Dim MyDirLeft As String
Dim MyDirTrim As String
Dim MyDirResult1 As String
Dim MyDirResult2 As String
Dim MyDirResult3 As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sQL16 As String
'On Error GoTo ErrorHandling
'Opens the Browse Dialog
With MyDlg
.TypeFile = 0 'All file Types
.TypeFile = 4 'Text Files
.DialogType = "Browse"
End With
'Show the select type of dialog selected with the properties
desired
MyDlg.Show
'The name for the chosen file or directory
'<Drive>:\Folder
GetFolder = MyDlg.ReturnFilePath
LenGetFolder = Len(GetFolder)
MidPathGetFolder = Mid(GetFolder, 4, LenGetFolder)
'<Drive>
strDrive = Left(GetFolder, 1)
'Initialize Variables
strDir = GetFolder & "\" & MidPathGetFolder & ".CRC"
SearchChar = "DIR"
MyCounterDir = 0
intFF = FreeFile
Open strDir For Input As #intFF
For i = 1 To 7 'Discard the first seven lines of the file
Line Input #intFF, ReadText
Next i
Do While Not EOF(intFF)
Input #intFF, ReadText
MyDirPos = InStr(1, ReadText, SearchChar, 1)
If MyDirPos = 1 Then
LenDir = Len(ReadText)
'DIR Folder\Folder\...
MySearchDirMid = Mid(ReadText, 1, LenDir)
MyDirResult1 = Trim(MySearchDirMid)
'Folder\
MyDir = Mid(ReadText, 4, LenDir)
MyDirResult2 = Trim(MyDir)
MyDirRev = InStrRev(MyDirResult2, "\", -1, vbTextCompare)
'Folder\Folder\...
MyDirLeft = Left(MyDir, MyDirRev)
MyDirTrim = Trim(MyDirLeft)
MyDirResult3 = GetFolder & "\" & MyDirTrim
MyCounterDir = MyCounterDir + 1
'Initialize Variables
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("Directories_" & strDrive &
"_Tbl", dbOpenDynaset)
With rs
.AddNew 'Add a new record
!ID = MyCounterDir
!SearchDir = MyDirResult1
!MyDirectories = MyDirResult2
!MyDirectoryPath = MyDirResult3
.Update 'Write the new record to the table
.Bookmark = .LastModified
End With
End If
Loop
Close #intFF
rs.Close
db.Close
Set db = Nothing
'This Query UPDATES Dir and C:\Dups V.1.0 WHERE the CRC File
contains "DIR" AND C:\Dups V.1.0\
'AND the File Name IS empty
sQL16 = _
"UPDATE Directories_" & strDrive & "_Tbl SET " & _
"MyDirectories = 'DIR', " & _
"MyDirectoryPath = 'C:\Dups V.1.0' " & _
"WHERE ((MyDirectories ='" & "" & "' ) " & _
"AND (MyDirectoryPath='C:\Dups V.1.0\'));"
CurrentDb.Execute sQL16, dbFailOnError

--
John Nurick [Microsoft Access MVP]

Please respond in the newsgroup and not by email.- Hide quoted text -

- Show quoted text -

Thank you very much!!!

Regards
Antonio Macias
 
Back
Top