R
rebelscum0000
Dear all,
I have a .txt file and I want to replace some lines
Results I want:
==============================
Search Type: Find Files
C:\Documents and Settings\Antonio Macias\Desktop
A:\
C:\
C:\Documents and Settings
C:\Downloads
C:\Dups V.1.0
C:\DVD APPZ X
C:\DVD Basic_8116
C:\HP PMD P
C:\HP PMD P II
C:\HP PMD S
C:\MSOCache
C:\NO OS 80 G
C:\Program Files
C:\WINDOWS
D:\
E:\
C:\Documents and Settings\All Users\Documents
C:\Documents and Settings\Antonio Macias\My Documents
C:\Documents and Settings\Antonio Macias\Desktop\Appz Moved
C:\Documents and Settings\Antonio Macias\Desktop\FIX DVD Basic_8116
C:\Documents and Settings\Antonio Macias\Desktop\Fix HP PMD S
C:\Documents and Settings\Antonio Macias\Desktop\Fix HP PMD S G
C:\Documents and Settings\Antonio Macias\Desktop\HP PMD S
Included Patterns: *nero*.*
This is my Original .txt File without modifications
----Start Original .txt File without modifications------
Specifications for Current Search
==============================
[ Session Options ]
Exclude Internet Cache Files: YES
Exclude Internet Cache Files (Duplicates): YES
Exclude Windows Folders: YES
Exclude Windows Folders (Duplicates): YES
Exclude in Program Files Folder: YES
Exclude Recycle Bin: YES
==============================
[ Search Options ]
==============================
Search Type: Find Files
Search Folder 1: C:\Documents and Settings\Antonio Macias\Desktop
Search Folder 2: A:\
Search Folder 3: C:\
Search Folder 4: C:\Documents and Settings
Search Folder 5: C:\Downloads
Search Folder 6: C:\Dups V.1.0
Search Folder 7: C:\DVD APPZ X
Search Folder 8: C:\DVD Basic_8116
Search Folder 9: C:\HP PMD P
Search Folder 10: C:\HP PMD P II
Search Folder 11: C:\HP PMD S
Search Folder 12: C:\MSOCache
Search Folder 13: C:\NO OS 80 G
Search Folder 14: C:\Program Files
Search Folder 15: C:\WINDOWS
Search Folder 16: D:\
Search Folder 17: E:\
Search Folder 18: C:\Documents and Settings\All Users\Documents
Search Folder 19: C:\Documents and Settings\Antonio Macias\My
Documents
Search Folder 20: C:\Documents and Settings\Antonio
Macias\Desktop\Appz Moved
Search Folder 21: C:\Documents and Settings\Antonio Macias\Desktop\FIX
DVD Basic_8116
Search Folder 22: C:\Documents and Settings\Antonio Macias\Desktop\Fix
HP PMD S
Search Folder 23: C:\Documents and Settings\Antonio Macias\Desktop\Fix
HP PMD S G
Search Folder 24: C:\Documents and Settings\Antonio Macias\Desktop\HP
PMD S
Included Patterns: *nero*.*
----End of the Original .txt File without modifications------
This is my code, which of course is not working; could someone please
help me to understand what I am doing wrong?
Thanks in Advance
Regards
Antonio Macias
----Code Start ------
Option Compare Database
Sub Reading_TxtFile_R()
Dim OriginTxtPath As String
Dim DestinationTxtPath As String
Dim inFile As Integer
Dim outFile As Integer
Dim ReadText As String
Dim PatternsLine As String
Dim SearchFolderLine As String
Dim MyCounter As Integer
OriginTxtPath = "C:\Program
Files\Fineware\hound4\Searches\LastSearch.txt"
DestinationTxtPath = "C:\Dups V.1.0\LastSearchMacias.txt"
PatternsLine = "Included Patterns:"
SearchFolderLine = "Search Folder"
MyCounter = 0
'Obtain legal handles
'inFile = FreeFile
'Open OriginTxtPath For Input As #inFile
inFile = FreeFile()
'Open the files: this needs to be error-trapped properly
Open OriginTxtPath For Input As #inFile
outFile = FreeFile()
Open DestinationTxtPath For Output As #outFile
Do Until EOF(inFile) 'Loop until end of file.
Line Input #inFile, ReadText 'Read line into variable.
'Then you can read it line by line:
'Do something with the line.
If Left(ReadText, Len(SearchFolderLine)) = SearchFolderLine Then
MsgBox "Found Search Folder"
MyCounter = MyCounter + 1
End If
For FolderLineFound = 1 To MyCounter
SearchFolderLineReplace = Replace(SearchFolderLine & _
" " & FolderLineFound & ":", SearchFolderLine & " " & FolderLineFound &
_
":", "DO SOMETHING PLEASE!!!", , , vbTextCompare)
Debug.Print SearchFolderLineReplace
Next
'Write it out to the DestinationTxtPath
Print #outFile, ReadText
Loop 'Now go round again for the next line
'tidy up
Close #inFile
Close #outFile
End Sub
I have a .txt file and I want to replace some lines
Results I want:
==============================
Search Type: Find Files
C:\Documents and Settings\Antonio Macias\Desktop
A:\
C:\
C:\Documents and Settings
C:\Downloads
C:\Dups V.1.0
C:\DVD APPZ X
C:\DVD Basic_8116
C:\HP PMD P
C:\HP PMD P II
C:\HP PMD S
C:\MSOCache
C:\NO OS 80 G
C:\Program Files
C:\WINDOWS
D:\
E:\
C:\Documents and Settings\All Users\Documents
C:\Documents and Settings\Antonio Macias\My Documents
C:\Documents and Settings\Antonio Macias\Desktop\Appz Moved
C:\Documents and Settings\Antonio Macias\Desktop\FIX DVD Basic_8116
C:\Documents and Settings\Antonio Macias\Desktop\Fix HP PMD S
C:\Documents and Settings\Antonio Macias\Desktop\Fix HP PMD S G
C:\Documents and Settings\Antonio Macias\Desktop\HP PMD S
Included Patterns: *nero*.*
This is my Original .txt File without modifications
----Start Original .txt File without modifications------
Specifications for Current Search
==============================
[ Session Options ]
Exclude Internet Cache Files: YES
Exclude Internet Cache Files (Duplicates): YES
Exclude Windows Folders: YES
Exclude Windows Folders (Duplicates): YES
Exclude in Program Files Folder: YES
Exclude Recycle Bin: YES
==============================
[ Search Options ]
==============================
Search Type: Find Files
Search Folder 1: C:\Documents and Settings\Antonio Macias\Desktop
Search Folder 2: A:\
Search Folder 3: C:\
Search Folder 4: C:\Documents and Settings
Search Folder 5: C:\Downloads
Search Folder 6: C:\Dups V.1.0
Search Folder 7: C:\DVD APPZ X
Search Folder 8: C:\DVD Basic_8116
Search Folder 9: C:\HP PMD P
Search Folder 10: C:\HP PMD P II
Search Folder 11: C:\HP PMD S
Search Folder 12: C:\MSOCache
Search Folder 13: C:\NO OS 80 G
Search Folder 14: C:\Program Files
Search Folder 15: C:\WINDOWS
Search Folder 16: D:\
Search Folder 17: E:\
Search Folder 18: C:\Documents and Settings\All Users\Documents
Search Folder 19: C:\Documents and Settings\Antonio Macias\My
Documents
Search Folder 20: C:\Documents and Settings\Antonio
Macias\Desktop\Appz Moved
Search Folder 21: C:\Documents and Settings\Antonio Macias\Desktop\FIX
DVD Basic_8116
Search Folder 22: C:\Documents and Settings\Antonio Macias\Desktop\Fix
HP PMD S
Search Folder 23: C:\Documents and Settings\Antonio Macias\Desktop\Fix
HP PMD S G
Search Folder 24: C:\Documents and Settings\Antonio Macias\Desktop\HP
PMD S
Included Patterns: *nero*.*
----End of the Original .txt File without modifications------
This is my code, which of course is not working; could someone please
help me to understand what I am doing wrong?
Thanks in Advance
Regards
Antonio Macias
----Code Start ------
Option Compare Database
Sub Reading_TxtFile_R()
Dim OriginTxtPath As String
Dim DestinationTxtPath As String
Dim inFile As Integer
Dim outFile As Integer
Dim ReadText As String
Dim PatternsLine As String
Dim SearchFolderLine As String
Dim MyCounter As Integer
OriginTxtPath = "C:\Program
Files\Fineware\hound4\Searches\LastSearch.txt"
DestinationTxtPath = "C:\Dups V.1.0\LastSearchMacias.txt"
PatternsLine = "Included Patterns:"
SearchFolderLine = "Search Folder"
MyCounter = 0
'Obtain legal handles
'inFile = FreeFile
'Open OriginTxtPath For Input As #inFile
inFile = FreeFile()
'Open the files: this needs to be error-trapped properly
Open OriginTxtPath For Input As #inFile
outFile = FreeFile()
Open DestinationTxtPath For Output As #outFile
Do Until EOF(inFile) 'Loop until end of file.
Line Input #inFile, ReadText 'Read line into variable.
'Then you can read it line by line:
'Do something with the line.
If Left(ReadText, Len(SearchFolderLine)) = SearchFolderLine Then
MsgBox "Found Search Folder"
MyCounter = MyCounter + 1
End If
For FolderLineFound = 1 To MyCounter
SearchFolderLineReplace = Replace(SearchFolderLine & _
" " & FolderLineFound & ":", SearchFolderLine & " " & FolderLineFound &
_
":", "DO SOMETHING PLEASE!!!", , , vbTextCompare)
Debug.Print SearchFolderLineReplace
Next
'Write it out to the DestinationTxtPath
Print #outFile, ReadText
Loop 'Now go round again for the next line
'tidy up
Close #inFile
Close #outFile
End Sub