sdruley
Well-known Member
- Joined
- Oct 3, 2010
- Messages
- 557
- Office Version
- 365
- Platform
- Windows
My task is simple. I want to
1) post a text stream into 4 text files in the folder C:\rainbowmike\
2) before the text stream can be posted to a text file, the old text file must be deleted and a new one created
3) Of the 4 text files in total, 2 files by the names of datafile.txt and triggerfile.txt must be moved to the root of "C:" after they are updated with new data.
My code works for steps 1 and 2 but I can't get step 3 to work. If anyone can figure out how to move two files to the C directory, that code would probably fit where the xxxx's are shown... over my head
Any help would be great. The FSO convention has always confused me but it seems to be fast and i need fast.
1) post a text stream into 4 text files in the folder C:\rainbowmike\
2) before the text stream can be posted to a text file, the old text file must be deleted and a new one created
3) Of the 4 text files in total, 2 files by the names of datafile.txt and triggerfile.txt must be moved to the root of "C:" after they are updated with new data.
My code works for steps 1 and 2 but I can't get step 3 to work. If anyone can figure out how to move two files to the C directory, that code would probably fit where the xxxx's are shown... over my head
Code:
Sub CreateFile(fName As String, c)
Dim FSO As New FileSystemObject
Dim ts As TextStream
If FSO.FileExists(fName) Then FSO.DeleteFile (fName) 'If file exists then delete it
Set ts = FSO.CreateTextFile(fName, True) ' Create a new file in it's place
ts.WriteLine (c) ' Fill the new file with information
ts.Close ' Disengage the pointer to the file
some 'xxxx if the fName is "c:\rainbowmike\datafile.txt" or "c:\rainbowmike\triggerfile.txt
code 'xxxx move these files to "c:\". FSO.MoveFile "datafile.txt", "c"\" should work
here 'xxxx but I can't get it to work unless, perhaps, I Dim FSO as FileSystemObject instead of New FileSystemObject
End Sub
Any help would be great. The FSO convention has always confused me but it seems to be fast and i need fast.