|
Prev: Copy file from server share to user profile
Next: "Permission Denied" error while copying files in Vista using VBScr
From: Kuldeep on 3 Jul 2008 04:21 I have a file "tmp.txt" in a format like word0, c:\1.txt word2, c:\2.txt word4, c:\Copy of tmp1.txt I need to delete all the files listed in 2nd column. I tried this script. Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") Wscript.Echo "File Name to be deleted : " & arrServiceList(1) strFilePath = "arrServiceList(1)" set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile(strFilePath) Loop It gives me Error on line "objFSO.DeleteFile(strFilePath)" File Not found. The files do exist in the specified path. If i hardcode the path in the script, It works fine. This is my first script. Please help Kuldeep
From: Bishop on 3 Jul 2008 05:08 try this: Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") Wscript.Echo "File Name to be deleted : " & arrServiceList(1) strFilePath = arrServiceList(1) If objFSO.FileExists(strFilePath) then objFSO.DeleteFile strFilePath,True End if Loop Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") Wscript.Echo "File Name to be deleted : " & arrServiceList(1) strFilePath = arrServiceList(1) If objFSO.FileExists(strFilePath) then objFSO.DeleteFile strFilePath,True End if Loop "Kuldeep" wrote: > I have a file "tmp.txt" in a format like > > word0, c:\1.txt > word2, c:\2.txt > word4, c:\Copy of tmp1.txt > > I need to delete all the files listed in 2nd column. > > I tried this script. > > Const ForReading = 1 > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > Do Until objTextFile.AtEndOfStream > strNextLine = objTextFile.Readline > arrServiceList = Split(strNextLine , ",") > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > strFilePath = "arrServiceList(1)" > set objFSO = CreateObject("Scripting.FileSystemObject") > objFSO.DeleteFile(strFilePath) > Loop > > It gives me Error on line "objFSO.DeleteFile(strFilePath)" > > File Not found. > > The files do exist in the specified path. If i hardcode the path in > the script, It works fine. > > This is my first script. > Please help > > Kuldeep >
From: Bishop on 3 Jul 2008 05:12 Sorry, my fault. try this: Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") Wscript.Echo "File Name to be deleted : " & arrServiceList(1) strFilePath = arrServiceList(1) If objFSO.FileExists(strFilePath) then objFSO.DeleteFile strFilePath,True End if Loop "Kuldeep" wrote: > I have a file "tmp.txt" in a format like > > word0, c:\1.txt > word2, c:\2.txt > word4, c:\Copy of tmp1.txt > > I need to delete all the files listed in 2nd column. > > I tried this script. > > Const ForReading = 1 > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > Do Until objTextFile.AtEndOfStream > strNextLine = objTextFile.Readline > arrServiceList = Split(strNextLine , ",") > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > strFilePath = "arrServiceList(1)" > set objFSO = CreateObject("Scripting.FileSystemObject") > objFSO.DeleteFile(strFilePath) > Loop > > It gives me Error on line "objFSO.DeleteFile(strFilePath)" > > File Not found. > > The files do exist in the specified path. If i hardcode the path in > the script, It works fine. > > This is my first script. > Please help > > Kuldeep >
From: Kuldeep on 3 Jul 2008 06:08 HI, Thanks for the reply. Now the Error message is gone. However the files are not deleted. Kuldeep On Jul 3, 2:12 pm, Bishop <Bis...(a)discussions.microsoft.com> wrote: > Sorry, my fault. > try this: > > Const ForReading = 1 > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > > Do Until objTextFile.AtEndOfStream > strNextLine = objTextFile.Readline > arrServiceList = Split(strNextLine , ",") > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > strFilePath = arrServiceList(1) > If objFSO.FileExists(strFilePath) then > objFSO.DeleteFile strFilePath,True > End if > Loop > > "Kuldeep" wrote: > > I have a file "tmp.txt" in a format like > > > word0, c:\1.txt > > word2, c:\2.txt > > word4, c:\Copy of tmp1.txt > > > I need to delete all the files listed in 2nd column. > > > I tried this script. > > > Const ForReading = 1 > > Set objFSO = CreateObject("Scripting.FileSystemObject") > > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > > Do Until objTextFile.AtEndOfStream > > strNextLine = objTextFile.Readline > > arrServiceList = Split(strNextLine , ",") > > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > > strFilePath = "arrServiceList(1)" > > set objFSO = CreateObject("Scripting.FileSystemObject") > > objFSO.DeleteFile(strFilePath) > > Loop > > > It gives me Error on line "objFSO.DeleteFile(strFilePath)" > > > File Not found. > > > The files do exist in the specified path. If i hardcode the path in > > the script, It works fine. > > > This is my first script. > > Please help > > > Kuldeep
From: Bishop on 3 Jul 2008 06:50
I find the problem. You use blanks in the file "tmp.txt" here is the solution with "Trim": Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") Wscript.Echo "File Name to be deleted : " & arrServiceList(1) strFilePath = Trim(arrServiceList(1)) If objFSO.FileExists(strFilePath) then objFSO.DeleteFile strFilePath,True End if Loop "Kuldeep" wrote: > HI, > Thanks for the reply. > Now the Error message is gone. However the files are not deleted. > > Kuldeep > > > On Jul 3, 2:12 pm, Bishop <Bis...(a)discussions.microsoft.com> wrote: > > Sorry, my fault. > > try this: > > > > Const ForReading = 1 > > Set objFSO = CreateObject("Scripting.FileSystemObject") > > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > > > > Do Until objTextFile.AtEndOfStream > > strNextLine = objTextFile.Readline > > arrServiceList = Split(strNextLine , ",") > > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > > strFilePath = arrServiceList(1) > > If objFSO.FileExists(strFilePath) then > > objFSO.DeleteFile strFilePath,True > > End if > > Loop > > > > "Kuldeep" wrote: > > > I have a file "tmp.txt" in a format like > > > > > word0, c:\1.txt > > > word2, c:\2.txt > > > word4, c:\Copy of tmp1.txt > > > > > I need to delete all the files listed in 2nd column. > > > > > I tried this script. > > > > > Const ForReading = 1 > > > Set objFSO = CreateObject("Scripting.FileSystemObject") > > > Set objTextFile = objFSO.OpenTextFile("c:\tmp.txt", ForReading) > > > Do Until objTextFile.AtEndOfStream > > > strNextLine = objTextFile.Readline > > > arrServiceList = Split(strNextLine , ",") > > > Wscript.Echo "File Name to be deleted : " & arrServiceList(1) > > > strFilePath = "arrServiceList(1)" > > > set objFSO = CreateObject("Scripting.FileSystemObject") > > > objFSO.DeleteFile(strFilePath) > > > Loop > > > > > It gives me Error on line "objFSO.DeleteFile(strFilePath)" > > > > > File Not found. > > > > > The files do exist in the specified path. If i hardcode the path in > > > the script, It works fine. > > > > > This is my first script. > > > Please help > > > > > Kuldeep > > |