Prev: convert input file with list of paths+filenames output to listof
Next: wait for external code to complete before continuing
From: Paul Randall on 12 May 2010 12:48 "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message news:D_zGn.3525$yx.3173(a)newsfe13.iad... > 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" Are you saying that after: >>> fso.deleteFile "C:\DATA\INdata.txt" and before: >>>> ofile2.close that: ofile2.name = "INdata.txt" won't work? -Paul Randall
From: "Dave "Crash" Dummy" on 12 May 2010 16:22 Paul Randall wrote: > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > news:D_zGn.3525$yx.3173(a)newsfe13.iad... >> 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" > > Are you saying that after: >>>> fso.deleteFile "C:\DATA\INdata.txt" > and before: >>>>> ofile2.close > that: > ofile2.name = "INdata.txt" > won't work? Yes. Write a test script and try it. -- Crash "The fewer the facts, the stronger the opinion." ~ Arnold H. Glasow ~
From: "Dave "Crash" Dummy" on 12 May 2010 20:15 Paul Randall wrote: > Are you saying that after: >>>> fso.deleteFile "C:\DATA\INdata.txt" > and before: >>>>> ofile2.close > that: > ofile2.name = "INdata.txt" > won't work? Yes. You are confusing a TextStream object with a File object. http://msdn.microsoft.com/en-us/library/312a5kbt(VS.85).aspx http://msdn.microsoft.com/en-us/library/1ft05taf(VS.85).aspx -- Crash "It's easier to ask forgiveness than it is to get permission." ~ Grace Hopper (RADM, USNR) ~
From: Paul Randall on 24 May 2010 16:22
"Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message news:WwHGn.3657$yx.3406(a)newsfe13.iad... > Paul Randall wrote: > >> Are you saying that after: >>>>> fso.deleteFile "C:\DATA\INdata.txt" >> and before: >>>>>> ofile2.close >> that: >> ofile2.name = "INdata.txt" >> won't work? > > Yes. You are confusing a TextStream object with a File object. > > http://msdn.microsoft.com/en-us/library/312a5kbt(VS.85).aspx > http://msdn.microsoft.com/en-us/library/1ft05taf(VS.85).aspx > -- > Crash You are right. I should have refreshed my memory from the scripting help file. Thanks for correcting me. -Paul Randall |