Re: Reading filename from a file and deleting by Al
Al
Sun Jul 06 15:16:26 CDT 2008
IMHO, the only space character that cannot be part of the filename is the
one following the comma. I would forget the trim, but change this:
arrServiceList = Split(strNextLine , ",")
to this:
arrServiceList = Split(strNextLine , ", ")
/Al
"Kuldeep" <kuldeep.kumar@gmail.com> wrote in message
news:cb1a2363-6301-4b14-8f29-15085ffa9809@25g2000hsx.googlegroups.com...
It works!!!
Thanks Bishop.
Your help is very much appreciated.
Kuldeep
On Jul 3, 3:50 pm, Bishop <Bis...@discussions.microsoft.com> wrote:
> 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...@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