I know a little about VBscript but am struggling with trying to figure out
how to do the following.

I need to delete all .xml files from a certain directory, however, I need to
delete only certain ones based off of client names.

Can anyone provide me with a script that will do this?
I have 30 clients that generate .xml files in this one directory, yet there
are other .xml files we need to leave alone. All client ID's are based on a
3 character name, for example, AMB, KRT, MLI, TXI, etc

I am trying to write the script to where it will (1) if files exissts then
delete amb*.xml, krt*.xml, etc

If possible, please send a reply to ken@txgeekman.com as well...

Thank you
K_Smith

Re: Help with vbscript please - delete files by mik3l3374

mik3l3374
Sat Sep 01 21:15:27 PDT 2007

On Sep 2, 9:58 am, "K_Smith" <k...@txgeekman.com> wrote:
> I know a little about VBscript but am struggling with trying to figure out
> how to do the following.
>
> I need to delete all .xml files from a certain directory, however, I need to
> delete only certain ones based off of client names.
>
> Can anyone provide me with a script that will do this?
> I have 30 clients that generate .xml files in this one directory, yet there
> are other .xml files we need to leave alone. All client ID's are based on a
> 3 character name, for example, AMB, KRT, MLI, TXI, etc
>
> I am trying to write the script to where it will (1) if files exissts then
> delete amb*.xml, krt*.xml, etc
>
> If possible, please send a reply to k...@txgeekman.com as well...
>
> Thank you
> K_Smith

what have you got so far?


Re: Help with vbscript please - delete files by K_Smith

K_Smith
Sat Sep 01 21:58:08 PDT 2007

I tried creating an array but it's not working, keep getting a mismatch type
error: - thanks

I can make it work if I write multiple lines checking for existance of each
file: Example:

if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\amb*.xml") Then

fs.deletefile "C:\Apps\Tomcat5.5\webapps\AU\amb*.xml"

end if

Below is what I attempted to make work. I'm sure writing the script to make
it do what I need is simple but I'm just not getting it. Any assistance you
can provide is greatly appreciated.



'create FileSystemObject Variable

Set fs = CreateObject("Scripting.FileSystemObject")

'DELETE AU XML files

dim clients(30)

clients(0)="amb*.xml"

clients(1)="asp*.xml"

clients(2)="bcp*.xml"

clients(3)="cap*.xml"

clients(4)="cop*.xml"

clients(5)="frg*.xml"

clients(6)="frp*.xml"

clients(7)="gib*.xml"

clients(8)="glb*.xml"

clients(9)="gmc*.xml"

clients(10)="har*.xml"

clients(11)="jpc*.xml"

clients(12)="kco*.xml"

clients(13)="krt*.xml"

clients(14)="lbr*.xml"

clients(15)="met*.xml"

clients(16)="mli*.xml"

clients(17)="mwc*.xml"

clients(18)="orc*.xml"

clients(19)="plt*.xml"

clients(20)="ptr*.xml"

clients(21)="ram*.xml"

clients(22)="rgi*.xml"

clients(23)="rqe*.xml"

clients(24)="sep*.xml"

clients(25)="smp*.xml"

clients(26)="sri*.xml"

clients(27)="srs*.xml"

clients(28)="tia*.xml"

clients(29)="jll*.xml"

For Each x in clients



if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\") & x Then

fs.deletefile x

end if

set fs=nothing

Next

<mik3l3374@gmail.com> wrote in message
news:1188706527.037192.178540@r34g2000hsd.googlegroups.com...
> On Sep 2, 9:58 am, "K_Smith" <k...@txgeekman.com> wrote:
>> I know a little about VBscript but am struggling with trying to figure
>> out
>> how to do the following.
>>
>> I need to delete all .xml files from a certain directory, however, I need
>> to
>> delete only certain ones based off of client names.
>>
>> Can anyone provide me with a script that will do this?
>> I have 30 clients that generate .xml files in this one directory, yet
>> there
>> are other .xml files we need to leave alone. All client ID's are based
>> on a
>> 3 character name, for example, AMB, KRT, MLI, TXI, etc
>>
>> I am trying to write the script to where it will (1) if files exissts
>> then
>> delete amb*.xml, krt*.xml, etc
>>
>> If possible, please send a reply to k...@txgeekman.com as well...
>>
>> Thank you
>> K_Smith
>
> what have you got so far?
>



Re: Help with vbscript please - delete files by John

John
Sat Sep 01 22:33:21 PDT 2007


"K_Smith" <ken@txgeekman.com> wrote in message news:%236Oca3R7HHA.4712@TK2MSFTNGP04.phx.gbl...
>I tried creating an array but it's not working, keep getting a mismatch type error: - thanks
>
> I can make it work if I write multiple lines checking for existance of each file: Example:
>
> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\amb*.xml") Then
>
> fs.deletefile "C:\Apps\Tomcat5.5\webapps\AU\amb*.xml"
>
> end if
>
> Below is what I attempted to make work. I'm sure writing the script to make it do what I need is simple but I'm just not getting
> it. Any assistance you can provide is greatly appreciated.
> For Each x in clients
>
>
>
> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\") & x Then
>
> fs.deletefile x
>
> end if
>
> set fs=nothing
>
> Next
>

Try:

For Each x in clients
sFilename = "c:\Apps\Tomcat5.5\webapps\AU\" & x
if fs.fileExists(sFilename) Then
fs.deletefile sFilename
end if
Next
set fs=nothing



Re: Help with vbscript please - delete files by mik3l3374

mik3l3374
Sat Sep 01 22:47:54 PDT 2007

strClients="amb|asp|bcp|cap|cop|frg" 'enter your clients 3 char code
here
arrClients = Split(strClients,"|")
Set objFSO=CreateObject("Scripting.FileSystemObject")
myFolder="C:\temp"
Set objFiles= objFSO.GetFolder(myFolder).Files
For Each myFile In objFiles
If objFSO.GetExtensionName(myFile) = "xml" Then
char=Mid(myFile.Name,1,3)
For i=LBound(arrClients) To UBound(arrClients)
If char = arrClients(i) Then
WScript.Echo arrClients(i)
' delete files code here....
End If
Next
End If
Next


Re: Help with vbscript please - delete files by K_Smith

K_Smith
Sat Sep 01 23:25:19 PDT 2007

Thanks but what's the code to delete the files?
I'm not clear on which variable I'm telling it to run through and delete.

I tried a few and nothing happens, no deleted files, no errors nothing
<mik3l3374@gmail.com> wrote in message
news:1188712074.075154.239290@57g2000hsv.googlegroups.com...
> strClients="amb|asp|bcp|cap|cop|frg" 'enter your clients 3 char code
> here
> arrClients = Split(strClients,"|")
> Set objFSO=CreateObject("Scripting.FileSystemObject")
> myFolder="C:\temp"
> Set objFiles= objFSO.GetFolder(myFolder).Files
> For Each myFile In objFiles
> If objFSO.GetExtensionName(myFile) = "xml" Then
> char=Mid(myFile.Name,1,3)
> For i=LBound(arrClients) To UBound(arrClients)
> If char = arrClients(i) Then
> WScript.Echo arrClients(i)
> ' delete files code here....
> End If
> Next
> End If
> Next
>



Re: Help with vbscript please - delete files by K_Smith

K_Smith
Sat Sep 01 23:25:47 PDT 2007

Thanks but nothing happens with that code, no deleted files, no errors,
nothing.


"John W" <johnXZwilliams.XZesquire@XZgmail.com> wrote in message
news:u72dnaBsV_m81kfbnZ2dnUVZ8t-nnZ2d@pipex.net...
>
> "K_Smith" <ken@txgeekman.com> wrote in message
> news:%236Oca3R7HHA.4712@TK2MSFTNGP04.phx.gbl...
>>I tried creating an array but it's not working, keep getting a mismatch
>>type error: - thanks
>>
>> I can make it work if I write multiple lines checking for existance of
>> each file: Example:
>>
>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\amb*.xml") Then
>>
>> fs.deletefile "C:\Apps\Tomcat5.5\webapps\AU\amb*.xml"
>>
>> end if
>>
>> Below is what I attempted to make work. I'm sure writing the script to
>> make it do what I need is simple but I'm just not getting it. Any
>> assistance you can provide is greatly appreciated.
>> For Each x in clients
>>
>>
>>
>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\") & x Then
>>
>> fs.deletefile x
>>
>> end if
>>
>> set fs=nothing
>>
>> Next
>>
>
> Try:
>
> For Each x in clients
> sFilename = "c:\Apps\Tomcat5.5\webapps\AU\" & x
> if fs.fileExists(sFilename) Then
> fs.deletefile sFilename
> end if
> Next
> set fs=nothing
>



Re: Help with vbscript please - delete files by K_Smith

K_Smith
Sat Sep 01 23:33:40 PDT 2007

let me make it a little more clear. The Client names are longer than just
three characters, example, AMB02key_126.xml

thanks again

<mik3l3374@gmail.com> wrote in message
news:1188712074.075154.239290@57g2000hsv.googlegroups.com...
> strClients="amb|asp|bcp|cap|cop|frg" 'enter your clients 3 char code
> here
> arrClients = Split(strClients,"|")
> Set objFSO=CreateObject("Scripting.FileSystemObject")
> myFolder="C:\temp"
> Set objFiles= objFSO.GetFolder(myFolder).Files
> For Each myFile In objFiles
> If objFSO.GetExtensionName(myFile) = "xml" Then
> char=Mid(myFile.Name,1,3)
> For i=LBound(arrClients) To UBound(arrClients)
> If char = arrClients(i) Then
> WScript.Echo arrClients(i)
> ' delete files code here....
> End If
> Next
> End If
> Next
>



Re: Help with vbscript please - delete files by mik3l3374

mik3l3374
Sat Sep 01 23:41:03 PDT 2007

On Sep 2, 2:25 pm, "K_Smith" <k...@txgeekman.com> wrote:
> Thanks but what's the code to delete the files?

that was meant for you to fill in yourself..Mr John W has already
shown you how to delete files.


Re: Help with vbscript please - delete files by John

John
Sun Sep 02 01:28:43 PDT 2007


"K_Smith" <ken@txgeekman.com> wrote in message news:OZn7VoS7HHA.5316@TK2MSFTNGP04.phx.gbl...
> Thanks but nothing happens with that code, no deleted files, no errors, nothing.
>
>
> "John W" <johnXZwilliams.XZesquire@XZgmail.com> wrote in message news:u72dnaBsV_m81kfbnZ2dnUVZ8t-nnZ2d@pipex.net...
>>
>> "K_Smith" <ken@txgeekman.com> wrote in message news:%236Oca3R7HHA.4712@TK2MSFTNGP04.phx.gbl...
>>>I tried creating an array but it's not working, keep getting a mismatch type error: - thanks
>>>
>>> I can make it work if I write multiple lines checking for existance of each file: Example:
>>>
>>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\amb*.xml") Then
>>>
>>> fs.deletefile "C:\Apps\Tomcat5.5\webapps\AU\amb*.xml"
>>>
>>> end if
>>>
>>> Below is what I attempted to make work. I'm sure writing the script to make it do what I need is simple but I'm just not
>>> getting it. Any assistance you can provide is greatly appreciated.
>>> For Each x in clients
>>>
>>>
>>>
>>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\") & x Then
>>>
>>> fs.deletefile x
>>>
>>> end if
>>>
>>> set fs=nothing
>>>
>>> Next
>>>
>>
>> Try:
>>
>> For Each x in clients
>> sFilename = "c:\Apps\Tomcat5.5\webapps\AU\" & x
>> if fs.fileExists(sFilename) Then
>> fs.deletefile sFilename
>> end if
>> Next
>> set fs=nothing
>>
>
>
Ah, okay. The problem is that fileExists matches wildcards in the filename, but deleteFile doesn't and therefore doesn't delete
anything.

You could do it by running a DOS delete command, which does match wildcards. Uncomment the shell.run line in the following code
to make it delete.

Option Explicit

Dim clients(29)

clients(0)="amb*.xml"
clients(1)="asp*.xml"
clients(2)="bcp*.xml"
clients(3)="cap*.xml"
clients(4)="cop*.xml"
clients(5)="frg*.xml"
clients(6)="frp*.xml"
clients(7)="gib*.xml"
clients(8)="glb*.xml"
clients(9)="gmc*.xml"
clients(10)="har*.xml"
clients(11)="jpc*.xml"
clients(12)="kco*.xml"
clients(13)="krt*.xml"
clients(14)="lbr*.xml"
clients(15)="met*.xml"
clients(16)="mli*.xml"
clients(17)="mwc*.xml"
clients(18)="orc*.xml"
clients(19)="plt*.xml"
clients(20)="ptr*.xml"
clients(21)="ram*.xml"
clients(22)="rgi*.xml"
clients(23)="rqe*.xml"
clients(24)="sep*.xml"
clients(25)="smp*.xml"
clients(26)="sri*.xml"
clients(27)="srs*.xml"
clients(28)="tia*.xml"
clients(29)="jll*.xml"

Dim sFolder, sFileSpec
Dim doscmd, shell

sFolder = "c:\Apps\Tomcat5.5\webapps\AU\"

Set shell = CreateObject("Wscript.Shell")

For Each sFileSpec in clients

doscmd = "del " & sFolder & sFilespec
WScript.Echo doscmd

'Run in normal window and wait for command to finish
'shell.Run "%comspec% /C " & doscmd, 1, True
Next



Re: Help with vbscript please - delete files by ThatsIT

ThatsIT
Sun Sep 02 04:16:32 PDT 2007

Try this
http://dev.thatsit.net.au/Samples/WSH/thatsIT/fso/deleteSomeFiles.asp


"K_Smith" <ken@txgeekman.com> wrote in message
news:eYQ%238SQ7HHA.4712@TK2MSFTNGP04.phx.gbl...
>I know a little about VBscript but am struggling with trying to figure out
>how to do the following.
>
> I need to delete all .xml files from a certain directory, however, I need
> to delete only certain ones based off of client names.
>
> Can anyone provide me with a script that will do this?
> I have 30 clients that generate .xml files in this one directory, yet
> there are other .xml files we need to leave alone. All client ID's are
> based on a 3 character name, for example, AMB, KRT, MLI, TXI, etc
>
> I am trying to write the script to where it will (1) if files exissts then
> delete amb*.xml, krt*.xml, etc
>
> If possible, please send a reply to ken@txgeekman.com as well...
>
> Thank you
> K_Smith
>


Re: Help with vbscript please - delete files by K_Smith

K_Smith
Sun Sep 02 06:56:15 PDT 2007

John

"Thank You!!!" this works great. I cannot thank you enough. This is going
to save us so much time during weekly maintenance on four servers.

Thanks to mik3l3374 as well. You're example helps me understand a little
better as well.

Hopefully I'll get better at vbscript.

Thanks again!!

"John W" <johnXZwilliams.XZesquire@XZgmail.com> wrote in message
news:JZadndXLG_eh6UfbnZ2dneKdnZydnZ2d@pipex.net...
>
> "K_Smith" <ken@txgeekman.com> wrote in message
> news:OZn7VoS7HHA.5316@TK2MSFTNGP04.phx.gbl...
>> Thanks but nothing happens with that code, no deleted files, no errors,
>> nothing.
>>
>>
>> "John W" <johnXZwilliams.XZesquire@XZgmail.com> wrote in message
>> news:u72dnaBsV_m81kfbnZ2dnUVZ8t-nnZ2d@pipex.net...
>>>
>>> "K_Smith" <ken@txgeekman.com> wrote in message
>>> news:%236Oca3R7HHA.4712@TK2MSFTNGP04.phx.gbl...
>>>>I tried creating an array but it's not working, keep getting a mismatch
>>>>type error: - thanks
>>>>
>>>> I can make it work if I write multiple lines checking for existance of
>>>> each file: Example:
>>>>
>>>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\amb*.xml") Then
>>>>
>>>> fs.deletefile "C:\Apps\Tomcat5.5\webapps\AU\amb*.xml"
>>>>
>>>> end if
>>>>
>>>> Below is what I attempted to make work. I'm sure writing the script to
>>>> make it do what I need is simple but I'm just not getting it. Any
>>>> assistance you can provide is greatly appreciated.
>>>> For Each x in clients
>>>>
>>>>
>>>>
>>>> if fs.fileExists("c:\Apps\Tomcat5.5\webapps\AU\") & x Then
>>>>
>>>> fs.deletefile x
>>>>
>>>> end if
>>>>
>>>> set fs=nothing
>>>>
>>>> Next
>>>>
>>>
>>> Try:
>>>
>>> For Each x in clients
>>> sFilename = "c:\Apps\Tomcat5.5\webapps\AU\" & x
>>> if fs.fileExists(sFilename) Then
>>> fs.deletefile sFilename
>>> end if
>>> Next
>>> set fs=nothing
>>>
>>
>>
> Ah, okay. The problem is that fileExists matches wildcards in the
> filename, but deleteFile doesn't and therefore doesn't delete anything.
>
> You could do it by running a DOS delete command, which does match
> wildcards. Uncomment the shell.run line in the following code to make it
> delete.
>
> Option Explicit
>
> Dim clients(29)
>
> clients(0)="amb*.xml"
> clients(1)="asp*.xml"
> clients(2)="bcp*.xml"
> clients(3)="cap*.xml"
> clients(4)="cop*.xml"
> clients(5)="frg*.xml"
> clients(6)="frp*.xml"
> clients(7)="gib*.xml"
> clients(8)="glb*.xml"
> clients(9)="gmc*.xml"
> clients(10)="har*.xml"
> clients(11)="jpc*.xml"
> clients(12)="kco*.xml"
> clients(13)="krt*.xml"
> clients(14)="lbr*.xml"
> clients(15)="met*.xml"
> clients(16)="mli*.xml"
> clients(17)="mwc*.xml"
> clients(18)="orc*.xml"
> clients(19)="plt*.xml"
> clients(20)="ptr*.xml"
> clients(21)="ram*.xml"
> clients(22)="rgi*.xml"
> clients(23)="rqe*.xml"
> clients(24)="sep*.xml"
> clients(25)="smp*.xml"
> clients(26)="sri*.xml"
> clients(27)="srs*.xml"
> clients(28)="tia*.xml"
> clients(29)="jll*.xml"
>
> Dim sFolder, sFileSpec
> Dim doscmd, shell
>
> sFolder = "c:\Apps\Tomcat5.5\webapps\AU\"
>
> Set shell = CreateObject("Wscript.Shell")
>
> For Each sFileSpec in clients
>
> doscmd = "del " & sFolder & sFilespec
> WScript.Echo doscmd
>
> 'Run in normal window and wait for command to finish
> 'shell.Run "%comspec% /C " & doscmd, 1, True
> Next
>