Kill not working (1 Viewer)

iain1978

Registered User.
Local time
Today, 11:50
Joined
Nov 26, 2004
Messages
30
Hi all,

I'm having problems with the kill comand.

Basically wanting VB to provide an archive function for a folder when some on a access DB says the records is closed. My basic code is below.

I keep on getting file not found error at the kill comand. Can anyone explain what I'm doing wrong?

the DIm ID is broughtr over from a previous form.

Private Sub Command0_Click()

Dim FSO As Object

Dim ID As String
Dim FromPath As String
Dim ToPath As String
Dim K1 As String

FromPath = "C:\test\open\" & ID '<< Change
ToPath = "C:\test\closed\" & ID '<< Change
K1 = "C:\test\open\" & ID & "*.*"

If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If


FSO.CopyFolder Source:=FromPath, Destination:=ToPath

Kill (K1)
RmDir (FromPath)


MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath

End Sub
 

DCrake

Remembered
Local time
Today, 11:50
Joined
Jun 8, 2005
Messages
8,632
Don't know whether the Kill command can delete more than one file at a time have you tried enumerating through the folder killing files one at a time then removing the folder.

Edit

Just tried it and yes you can kill more than one file. I put 2 txt files in a folder then typed in

Kill "C:\Temp\*.txt"

And they both got deleted.

David
 
Last edited:

iain1978

Registered User.
Local time
Today, 11:50
Joined
Nov 26, 2004
Messages
30
Thanks for the reply.

I will give it a try, although I'm not to sure if it will help.

If i write the code with a direct refrence (i.e "C:\test\closed\6\*.*" instead of "C:\test\open\" & ID & "*.*") it works fine.
 

DJkarl

Registered User.
Local time
Today, 05:50
Joined
Mar 16, 2007
Messages
1,028
based on these lines I'm guessing that ID is a complete file name, i.e. test.txt

Code:
FromPath = "C:\test\open\" & ID '<< Change
ToPath = "C:\test\closed\" & ID '<< Change
K1 = "C:\test\open\" & ID & "*.*"

so when you try to add *.* to the file maybe you end up with test.txt.*.* ?
 

iain1978

Registered User.
Local time
Today, 11:50
Joined
Nov 26, 2004
Messages
30
the ID is a number. The number that relates to the DB record currently beiong looked at.
 

Users who are viewing this thread

Top Bottom