"Dave "Crash" Dummy" <invalid@newsgroup> wrote in message
news:TLvGn.8716$TL5.3404@newsgroup
> williamkow wrote:
>> Can you advise me on how to delete a file and then rename a file using
>> vbs, but without using WMI class. Many thanks in advance.
>>
>> set fsoA = WScript.CreateObject("Scripting.FileSystemObject")
>> set fsoB = WScript.CreateObject("Scripting.FileSystemObject")
>> set fsoC = WScript.CreateObject("Scripting.FileSystemObject")
>>
>> set ifile1 = fsoA.OpenTextFile("C:\DATA\INdata.txt", 1, False)
>> set ofile1 = fsoB.CreateTextFile("C:\DATA\OUTFILE1.txt", True)
>> set ofile2 = fsoC.CreateTextFile("C:\DATA\OUTFILE2.txt", True)
>>
>> If ofile1.FileExists(inFile) Then
>> '..... read the ifile1, then processing, output to ofile1 and ofile2
>> ofile1.writeline ....
>> ofile2.writeline ....
>> End If
>>
>> ' how to delete the INdata.txt
>> ' how to rename the OUTFILE2.txt to INdata.txt ifile1.Close
>> ofile1.close
>> ofile2.close >
> First of all, you only need one File System Object. Then, after all files
> are closed,
>
> fso.deleteFile "C:\DATA\INdata.txt"
> fso.MoveFile "C:\DATA\OUTFILE2.txt","C:\DATA\INdata.txt" Besides fso.MoveFile, you can also use something like:
ofile2.name = "INdata.txt"
The scripting help file says this about the name property:
Sets or returns the name of a specified file or folder. Read/write.
object.Name [= newname]
-Paul Randall