I would like to open a .txt file and save it with the same name but with an .xml extension. I think that that bit is fairly straightforwad but what I can't do is to do this for all the .txt files in a directory/folder. Please help.
One way to process all of the files in a directory (which I believe you are trying to do), is to use the dir function to create a text file which lists all files you require. Then use this newly created text file to open & process the correct files:
sub Process Files
Dim strFileName as String
Open "c:\list1.txt" For Input As #1
Do
Line Input #1, strFileName
'Add processing code here
Perhaps the quickest way of creating the list is to goto the dos prompt, & use the Dir command as follows. I generally navigate through to the source folder from the command prompt, rather than creating a more complicated Dir command.
e.g.
I want a list of files in c:\James\TextFilesI would open a command prompt, then use the cd command to navigate to c:\James\TextFiles\:
cd james\textfiles
At this point I would run the following Dir command:
Dir *.txt /b >c:\list1.txt
This should create a text file, (list1.txt).
You can then use the following sub to rename all of the files listed in the list1.txt file: (Be sure to change the const declaration to your folder name)
Sub ProcessFiles()
On Error GoTo Process_Err
Dim strFileName As String
Dim pos As Integer, dFileName As String
Const SourceDir As String = "c:\James\TextFiles\"
'Open the list file
Open "c:\list1.txt" For Input As #1
'Setup a loop
Do
Line Input #1, strFileName
'Get the position of the file extension (only where it is .txt)
pos = InStr(strFileName, ".txt"
'If the file is a .txt file, process it
If pos > 0 Then
'Construct the new filename
dFileName = Left(strFileName, pos - 1) & ".xml"
'Rename the old file
Name (SourceDir & strFileName) As (SourceDir & dFileName)
Else
'Perhaps not a text file, do nothing
End If
porben,
you need to start a new thread if you want answers to this question. This thread is old and not really relevant to what you want to know.
When you start it, you will need to give more information too. What do you want to convert your word files to? What do you mean put it on a dB? Just load the filenames or copy data from a word file into your database?
A good question is one that has enough information to work out what you want without having to go back and ask for more information.
Remember a good question is more likely to get answered.
Ben ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
Go into your forum & at the top of the list of threads there is "Start A New Thread" or something similar.
It's not the most obvious link in the world, but it's there!
B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.