|
-
Oct 10th, 2002, 11:49 AM
#1
Thread Starter
Addicted Member
Deleting Text File
hi, anyone noe whats the code i have to write when i want to del a text file Eg:baby.txt .....
-
Oct 10th, 2002, 11:52 AM
#2
-
Oct 10th, 2002, 11:52 AM
#3
PowerPoster
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 10th, 2002, 11:59 AM
#4
Thread Starter
Addicted Member
-
Oct 10th, 2002, 11:59 AM
#5
-
Oct 10th, 2002, 12:12 PM
#6
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.
-
Oct 10th, 2002, 12:13 PM
#7
-
Oct 10th, 2002, 12:30 PM
#8
Ask And Ye Shall Receive...this function gives you the option
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
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.
-
Oct 10th, 2002, 01:35 PM
#9
Fanatic Member
Lol
You call that a bit more code?
1 line,
8712638971236 lines....
Hehehe... Anyways, could be useful, I'll check that out, thx!
-
Oct 10th, 2002, 06:16 PM
#10
Software Eng.
It may seem like a bit more, but it really wont make any difference in terms of speed or size.
-
Oct 10th, 2002, 06:54 PM
#11
Frenzied Member
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 ) 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!!!!!!!
Beantown Boy
Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
-
Oct 10th, 2002, 07:32 PM
#12
Addicted Member
Well he may not be standard, but I didn't have any trouble understanding it.
Stephen Boston
Onward!
 VB6 Pro SP4, VBScript
A+ Certified Techncian.
No matter where you go, there you are.
-
Oct 10th, 2002, 08:18 PM
#13
Addicted Member
-------------------------
My name says it all!
-
Oct 10th, 2002, 09:42 PM
#14
-Lou
Originally posted by SeanK
yadayadayada....
Private Enum WhatDoIDoWithIt
SendToRecycle = 1
WhackIt = 2
End Enum
....
You really should try the [vbcode]...[/vbcode] tags
VB Code:
Private Enum WhatDoIDoWithIt
SendToRecycle = 1
WhackIt = 2
End Enum
-
Oct 11th, 2002, 10:21 AM
#15
Fanatic Member
reply
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
-
Oct 11th, 2002, 10:44 AM
#16
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.
-
Oct 11th, 2002, 12:38 PM
#17
Originally posted by SeanK
I would never get stuff like that by my boss in a zillion years!!!!!!!
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!
-
Oct 11th, 2002, 12:41 PM
#18
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!
Hear! Hear!
Some where I actualy have production code that reads as follows....
It was before we enacted strict standards here and such things have never been cleaned up....
-
Oct 11th, 2002, 01:05 PM
#19
Addicted Member
I manage the development team at our business, it wouldn't pass my muster either. But I understood his code just fine.
Stephen Boston
Onward!
 VB6 Pro SP4, VBScript
A+ Certified Techncian.
No matter where you go, there you are.
-
Oct 11th, 2002, 01:07 PM
#20
-
Oct 11th, 2002, 01:12 PM
#21
Addicted Member
You betcha!
Stephen Boston
Onward!
 VB6 Pro SP4, VBScript
A+ Certified Techncian.
No matter where you go, there you are.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|