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

RE: Reading filename from a file and deleting by Bishop

Bishop
Thu Jul 03 04:08:01 CDT 2008

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
>

RE: Reading filename from a file and deleting by Bishop

Bishop
Thu Jul 03 04:12:02 CDT 2008

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
>

Re: Reading filename from a file and deleting by Kuldeep

Kuldeep
Thu Jul 03 05:08:23 CDT 2008

HI,
Thanks for the reply.
Now the Error message is gone. However the files are not deleted.

Kuldeep


On Jul 3, 2:12=A0pm, Bishop <Bis...@discussions.microsoft.com> wrote:
> Sorry, my fault.
> try this:
>
> Const ForReading =3D 1
> Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> Set objTextFile =3D objFSO.OpenTextFile("c:\tmp.txt", ForReading)
>
> Do Until objTextFile.AtEndOfStream
> =A0 =A0 strNextLine =3D objTextFile.Readline
> =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> =A0 =A0 Wscript.Echo "File Name to be deleted =A0: =A0" & arrServiceList(1=
)
> =A0 =A0 strFilePath =3D arrServiceList(1)
> =A0 =A0 If objFSO.FileExists(strFilePath) then
> =A0 =A0 =A0 =A0 =A0 =A0 objFSO.DeleteFile strFilePath,True
> =A0 =A0 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 =3D 1
> > Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > Set objTextFile =3D objFSO.OpenTextFile("c:\tmp.txt", ForReading)
> > Do Until objTextFile.AtEndOfStream
> > =A0 =A0 strNextLine =3D objTextFile.Readline
> > =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> > =A0 =A0 Wscript.Echo "File Name to be deleted =A0: =A0" & arrServiceList=
(1)
> > =A0 =A0 strFilePath =3D "arrServiceList(1)"
> > =A0 =A0 set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > =A0 =A0 objFSO.DeleteFile(strFilePath)
> > Loop
>
> > It gives me Error =A0on 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


Re: Reading filename from a file and deleting by Bishop

Bishop
Thu Jul 03 05:50:00 CDT 2008

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
>
>

Re: Reading filename from a file and deleting by Kuldeep

Kuldeep
Thu Jul 03 06:52:23 CDT 2008

It works!!!
Thanks Bishop.
Your help is very much appreciated.

Kuldeep


On Jul 3, 3:50=A0pm, 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 =3D 1
> Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> Set objTextFile =3D objFSO.OpenTextFile("c:\tmp.txt", ForReading)
>
> Do Until objTextFile.AtEndOfStream
> =A0 =A0 strNextLine =3D objTextFile.Readline
> =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> =A0 =A0 Wscript.Echo "File Name to be deleted =A0: =A0" & arrServiceList(=
1)
> =A0 =A0 strFilePath =3D Trim(arrServiceList(1))
> =A0 =A0 If objFSO.FileExists(strFilePath) then
> =A0 =A0 =A0 =A0 =A0 =A0 objFSO.DeleteFile strFilePath,True
> =A0 =A0 End if
> Loop
>
> "Kuldeep" wrote:
> > HI,
> > =A0 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 =3D 1
> > > Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > > Set objTextFile =3D objFSO.OpenTextFile("c:\tmp.txt", ForReading)
>
> > > Do Until objTextFile.AtEndOfStream
> > > =A0 =A0 strNextLine =3D objTextFile.Readline
> > > =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> > > =A0 =A0 Wscript.Echo "File Name to be deleted =A0: =A0" & arrServiceL=
ist(1)
> > > =A0 =A0 strFilePath =3D arrServiceList(1)
> > > =A0 =A0 If objFSO.FileExists(strFilePath) then
> > > =A0 =A0 =A0 =A0 =A0 =A0 objFSO.DeleteFile strFilePath,True
> > > =A0 =A0 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 =3D 1
> > > > Set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > > > Set objTextFile =3D objFSO.OpenTextFile("c:\tmp.txt", ForReading)
> > > > Do Until objTextFile.AtEndOfStream
> > > > =A0 =A0 strNextLine =3D objTextFile.Readline
> > > > =A0 =A0 arrServiceList =3D Split(strNextLine , ",")
> > > > =A0 =A0 Wscript.Echo "File Name to be deleted =A0: =A0" & arrServic=
eList(1)
> > > > =A0 =A0 strFilePath =3D "arrServiceList(1)"
> > > > =A0 =A0 set objFSO =3D CreateObject("Scripting.FileSystemObject")
> > > > =A0 =A0 objFSO.DeleteFile(strFilePath)
> > > > Loop
>
> > > > It gives me Error =A0on 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


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