hi, anyone noe whats the code i have to write when i want to del a text file Eg:baby.txt .....
Printable View
hi, anyone noe whats the code i have to write when i want to del a text file Eg:baby.txt .....
Kill baby.txt
VB Code:
KILL c:\baby.text
thx alot guys
VB Code:
Kill "c:\baby.txt"
Please remember Kill will not send your file to the Recyle Bin. It flat whacks it. There is a way to delete a file that will send it to the recycle bin, therefore, making it available for restoration, but if involves a bit more code. I have a Function that I use for these cases. If you are interested, let me know and I'll post it.
I'd be interested.
The FOF_CREATEPROGRESSDLG is optional, but I like it. It pops up the message box asking if you want to send the file to the recycle bin, or if you are sure you want to delete it.VB Code:
Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Boolean hNameMappings As Long lpszProgressTitle As String End Type Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Const FO_DELETE = &H3 Private Const FOF_ALLOWUNDO = &H40 Private Const FOF_CREATEPROGRESSDLG As Long = &H0 Private Enum WhatDoIDoWithIt SendToRecycle = 1 WhackIt = 2 End Enum Private Function TrashFile(FileName As String, How As WhatDoIDoWithIt) As Boolean Dim FileOperation As SHFILEOPSTRUCT Dim RetCode As Long On Error GoTo WhackItError With FileOperation .wFunc = FO_DELETE .pFrom = FileName If How = SendToRecycle Then .fFlags = FOF_ALLOWUNDO + FOF_CREATEPROGRESSDLG Else .fFlags = FO_DELETE + FOF_CREATEPROGRESSDLG End If End With RetCode = SHFileOperation(FileOperation) If RetCode <> 0 Then TrashFile = False Else TrashFile = True End If Exit Function WhackItError: TrashFile = False MsgBox Err & " " & Error End Function Private Sub Command1_Click() 'to delete it entirely, as with Kill TrashFile "c:\baby.txt", WhackIt 'or to send it to the recycle bin TrashFile "c:\baby.txt", SendToRecycle End Sub
You call that a bit more code?
1 line,
8712638971236 lines....
Hehehe... Anyways, could be useful, I'll check that out, thx!
It may seem like a bit more, but it really wont make any difference in terms of speed or size.
Cool code Hack, but I've been dyin' to ask you a question. A lot, if not most, of the code you post does not follow any standard naming conventions I've ever heard of.
At the risk of having a moderator consider this Chit Chat (look at what happened to your Listbox post :rolleyes: ) I'd like to know if your function is an example of how you write production code???
I mean:
Private Enum WhatDoIDoWithIt
SendToRecycle = 1
WhackIt = 2
End Enum
and
Private Function TrashFile(FileName As String, How As WhatDoIDoWithIt) As Boolean
TrashFile?
WhatDoIDoWithIt?
WhackIt?
How As WhatDoIDoWithIt?
I would never get stuff like that by my boss in a zillion years!!!!!!!
Well he may not be standard, but I didn't have any trouble understanding it. :D
Tag - Cool Function
-LouYou really should try the [vbcode]...[/vbcode] tagsQuote:
Originally posted by SeanK
yadayadayada....
Private Enum WhatDoIDoWithIt
SendToRecycle = 1
WhackIt = 2
End Enum
....
VB Code:
Private Enum WhatDoIDoWithIt SendToRecycle = 1 WhackIt = 2 End Enum
;)
simple as this
Kill "C:\WINDOWS\Desktop\example.txt"
edit: you can always change the directory and you can delete viruses and other things not just text. but dont go malicious
duc: I see that you are a new member and I know you are anxious to answer questions, but if you read the first few posts in the thread you will see that essentially the same answer was already given.
Neither would I! My production code follows all the standard variable and parameter etc naming conventions, but when I post code on the forum, I like to have a little fun! :DQuote:
Originally posted by SeanK
I would never get stuff like that by my boss in a zillion years!!!!!!!
Hear! Hear!Quote:
Originally posted by Hack
Neither would I! My production code follows all the standard variable and parameter etc naming conventions, but when I post code on the forum, I like to have a little fun! :D
Some where I actualy have production code that reads as follows....
VB Code:
Dim Bulb as Boolean
It was before we enacted strict standards here and such things have never been cleaned up....
:) I manage the development team at our business, it wouldn't pass my muster either. But I understood his code just fine.
And that's the most importaint part here....Quote:
Originally posted by Stephenb
:) But I understood his code just fine.
:D :p :cool:
You betcha! :)