Prev: convert input file with list of paths+filenames output to listof
Next: wait for external code to complete before continuing
From: williamkow on 12 May 2010 02:41 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
From: Pegasus [MVP] on 12 May 2010 05:08 "williamkow" <williamkow(a)discussions.microsoft.com> wrote in message news:3875F133-6BBD-4293-982F-5A09C88C084E(a)microsoft.com... > 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 You can use the Delete and the MoveFile methods of the File System Object. Download the helpfile script56.chm from the Microsoft site to see the exact syntax and some examples.
From: "Dave "Crash" Dummy" on 12 May 2010 06:52 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" -- Crash Morals allow predatory animals to live in large herds.
From: Paul Randall on 12 May 2010 10:28 "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message news:TLvGn.8716$TL5.3404(a)newsfe24.iad... > 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
From: "Dave "Crash" Dummy" on 12 May 2010 11:41
Paul Randall wrote: > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > news:TLvGn.8716$TL5.3404(a)newsfe24.iad... >> 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] Not quite. You have set the file as an object, first: set oFile=fso.getFile("OUTFILE2.txt") oFile.name="INdata.txt" -- Crash "The fewer the facts, the stronger the opinion." ~ Arnold H. Glasow ~ |