Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 delete a file in vb script

Author  Topic 

dasu
Posting Yak Master

104 Posts

Posted - 2004-09-14 : 07:48:24
Please tell me the solution for
delete all the files which name has following characters
jobid_filename
like
jobid=122
then

122_filename

i want to delete all the files preceded by this jobid
this file is there in another directory
plase suggest me the vbscript code for this

<edit> moved to developer forum </edit>

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-14 : 07:57:43
maybe this:

delete from
MyTable
where jobid like '%122_%'

but you could do in command line
del *122_*.*


Go with the flow & have fun! Else fight the flow
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-09-14 : 08:10:33
or vbscript like this.

--*****************************
[CODE]
Public objFileSystem
Set objFileSystem = WScript.CreateObject("Scripting.FileSystemObject")

Main

Set objFileSystem = Nothing


Sub Main()

' Get the Deletion Pattern
If WScript.Arguments.Count < 1 Then
Pattern = InputBox("What is the search string of the files that you want to delete")
If Pattern = "" Then
Exit Sub
End If
Else
Pattern = WScript.Arguments(0)
End If

On Error Resume Next

objFileSystem.DeleteFile Pattern, True

On Error GoTo 0

' get EQ domain files moved
End Sub
[/CODE]

save this into a .vbs file
then from the command prompt type filename.vbs 122_*.*

Hopefully this works :)



Duane.
Go to Top of Page

dasu
Posting Yak Master

104 Posts

Posted - 2004-09-16 : 06:25:02
i got the solution i think it s useful for others now
iam posting the answer.
this is the way
strOutSpoolPath=DTSGlobalVariables("gstrHomeDir").Value&"\feeds\outboundspool\"&DTSGlobalVariables("gstrFilePath").Value
if(objFso.FolderExists(strOutSpoolPath)) then
set objFolder =objFso.GetFolder( strOutSpoolPath)
set colFiles =objFolder.Files
if colFiles.Count > 0 then
For Each objFile in colFiles
Set objFso = CreateObject("Scripting.Filesystemobject")
strFile=objFile.name

if (CINT( left(strFile,DTSGlobalVariables("gintCount").Value))=(DTSGlobalVariables("gintJobId").Value)) then
If (objFso.FileExists(strOutSpoolPath&strFile) )then
DTSGlobalVariables("gstrErrorOutputFile").Value="Error_" & strFile
strErrAbslPath=DTSGlobalVariables("gstrHomeDir").Value&"\feeds\errors\"&DTSGlobalVariables("gstrFilePath").Value&DTSGlobalVariables("gstrErrorOutputFile").Value
strFile = strOutSpoolPath&strFile
objFso.MoveFile strFile ,strErrAbslPath
end if
end if
next
end if
end if
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-09-16 : 06:42:34
Hi Dasu,
You would probably had a quicker solution to your problem - If you had mentioned that the vbscript was to be in an activex task and put in the dts forum.



Duane.
Go to Top of Page

dasu
Posting Yak Master

104 Posts

Posted - 2004-09-16 : 10:01:18
hello,
duane can u tell me the dts forum id clearly please
regards
dasu.g
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-09-16 : 10:05:24
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=13



Duane.
Go to Top of Page
   

- Advertisement -