jtrapat1
asked on
Deleting A Text File From VB Application
I'm using VB6 against an SQL Server 7 database.
I'm trying to delete a text file and I'm using the Kill command.
I tried a lot of different syntaxes from MSDN, etc. but I still get an error: "File Not Found"
I shouldn't have any permissions problems.
I'm just trying to delete a text file from my C:\ drive.
ex: Kill "c:\test.txt"
What am I doing wrong?
Or, is there another way to delete a text file from a vb program?
Thanks in Advance
John
I'm trying to delete a text file and I'm using the Kill command.
I tried a lot of different syntaxes from MSDN, etc. but I still get an error: "File Not Found"
I shouldn't have any permissions problems.
I'm just trying to delete a text file from my C:\ drive.
ex: Kill "c:\test.txt"
What am I doing wrong?
Or, is there another way to delete a text file from a vb program?
Thanks in Advance
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could also use the FileSystemObject to delete the file.
'Set reference to Microsoft Scripting RunTime
DeleteFile "C:\test.txt"
Private Sub DeleteFile(ByVal sFilePath As String)
Dim oFso As New FileSystemObject
If oFso.FileExists(sFilePath) Then
oFso.DeleteFile(sFilePath)
End If
Set oFso = Nothing
End Sub
'Set reference to Microsoft Scripting RunTime
DeleteFile "C:\test.txt"
Private Sub DeleteFile(ByVal sFilePath As String)
Dim oFso As New FileSystemObject
If oFso.FileExists(sFilePath)
oFso.DeleteFile(sFilePath)
End If
Set oFso = Nothing
End Sub
Just a question: why all programmers are in love with a monstruosity like FSO to do really a simple job like delete a file?
It's like kill a fly with a machine gun :)
It's like kill a fly with a machine gun :)
its an alternat solution is all Richie.
I agree that using kill is more efficient. However, he is having a problem with it because the file doens't exist at that specified path. So I just presented an alternate solution.
I agree that using kill is more efficient. However, he is having a problem with it because the file doens't exist at that specified path. So I just presented an alternate solution.
Is the VB program running locally or on the server?
Is the file on the C: local or on the server?
========================== ==
If the VB program is running on a system other than the one where the file (to be deleted) resides, you will need more than just a simple Kill command. For that matter, you will need more than just the FSO object.
Example:
VB program running locally needs a shared access to the root directory of the server. Then the VB program can issue a command to delete the file:
Kill "\\NameOfServer\C$\test.tx t"
where C$ is a file share name mapped to C:\ on the server.
Alternatively, you could invoke a stored procedure (through ADO) on the server that would deleted the file.
Is the file on the C: local or on the server?
==========================
If the VB program is running on a system other than the one where the file (to be deleted) resides, you will need more than just a simple Kill command. For that matter, you will need more than just the FSO object.
Example:
VB program running locally needs a shared access to the root directory of the server. Then the VB program can issue a command to delete the file:
Kill "\\NameOfServer\C$\test.tx
where C$ is a file share name mapped to C:\ on the server.
Alternatively, you could invoke a stored procedure (through ADO) on the server that would deleted the file.
Hi
Try the following:
Dim objFile as FileSystemObject
Dim strFileLocation as String 'holds the file path
Dim strFileName as String 'holds the file name
objFile.Deletefile StrFileLocation, strFileName, true
Hope it works (does on my side)
Carl
Try the following:
Dim objFile as FileSystemObject
Dim strFileLocation as String 'holds the file path
Dim strFileName as String 'holds the file name
objFile.Deletefile StrFileLocation, strFileName, true
Hope it works (does on my side)
Carl
jtrapat1,
Now that an answer has been proposed, you are likely to get very few new comments on solutions to your problem. If you we've solved your problem, please select the best comment or answer. Otherwise, reject the proposed answer and respond to my questions.
Now that an answer has been proposed, you are likely to get very few new comments on solutions to your problem. If you we've solved your problem, please select the best comment or answer. Otherwise, reject the proposed answer and respond to my questions.
Hi Iknownothing, welcome to EE. Please, before post a comment/answer read the guidelines at bottom of this page.
by the way, don't post an "answer" that was already posted by other participant.
Cheers
by the way, don't post an "answer" that was already posted by other participant.
Cheers
ASKER
Decided to go with another proposed solution.
My apologies to my over zealousness. Although I have asked a few questions in the past, this is the first answer I decided to supply. Sorry guys!
And especially Sorry to raizon, I did not realise you already gave the answer before I did.
Carl
And especially Sorry to raizon, I did not realise you already gave the answer before I did.
Carl
no worries Iknownothing.
Common practice when posting is to post as a comment. This will allow the questioner to accept the answer that best fits their needs.
Common practice when posting is to post as a comment. This will allow the questioner to accept the answer that best fits their needs.
MsgBox FileName
to look what is actually placed there.
Sincerely,
Crin