SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 delete a file in vb script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dasu
Posting Yak Master

104 Posts

Posted - 09/14/2004 :  07:48:24  Show Profile  Reply with Quote
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

Slovenia
11749 Posts

Posted - 09/14/2004 :  07:57:43  Show Profile  Visit spirit1's Homepage  Reply with Quote
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

Edited by - spirit1 on 09/14/2004 08:02:44
Go to Top of Page

ditch
Flowing Fount of Yak Knowledge

South Africa
1466 Posts

Posted - 09/14/2004 :  08:10:33  Show Profile  Visit ditch's Homepage  Reply with Quote
or vbscript like this.

--*****************************

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


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 - 09/16/2004 :  06:25:02  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

South Africa
1466 Posts

Posted - 09/16/2004 :  06:42:34  Show Profile  Visit ditch's Homepage  Reply with Quote
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 - 09/16/2004 :  10:01:18  Show Profile  Reply with Quote
hello,
duane can u tell me the dts forum id clearly please
regards
dasu.g
Go to Top of Page

ditch
Flowing Fount of Yak Knowledge

South Africa
1466 Posts

Posted - 09/16/2004 :  10:05:24  Show Profile  Visit ditch's Homepage  Reply with Quote
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=13



Duane.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000