Results 1 to 21 of 21

Thread: Deleting Text File

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    254

    Deleting Text File

    hi, anyone noe whats the code i have to write when i want to del a text file Eg:baby.txt .....

  2. #2

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. KILL c:\baby.text
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    254
    thx alot guys

  5. #5

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.

  7. #7

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Ask And Ye Shall Receive...this function gives you the option

    VB Code:
    1. Private Type SHFILEOPSTRUCT
    2.     hWnd As Long
    3.     wFunc As Long
    4.     pFrom As String
    5.     pTo As String
    6.     fFlags As Integer
    7.     fAnyOperationsAborted As Boolean
    8.     hNameMappings As Long
    9.     lpszProgressTitle As String
    10. End Type
    11.  
    12. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    13.  
    14. Private Const FO_DELETE = &H3
    15. Private Const FOF_ALLOWUNDO = &H40
    16. Private Const FOF_CREATEPROGRESSDLG As Long = &H0
    17.  
    18. Private Enum WhatDoIDoWithIt
    19.     SendToRecycle = 1
    20.     WhackIt = 2
    21. End Enum
    22.  
    23. Private Function TrashFile(FileName As String, How As WhatDoIDoWithIt) As Boolean
    24.     Dim FileOperation As SHFILEOPSTRUCT
    25.     Dim RetCode As Long
    26.     On Error GoTo WhackItError
    27.     With FileOperation
    28.         .wFunc = FO_DELETE
    29.         .pFrom = FileName
    30.         If How = SendToRecycle Then
    31.             .fFlags = FOF_ALLOWUNDO + FOF_CREATEPROGRESSDLG
    32.         Else
    33.             .fFlags = FO_DELETE + FOF_CREATEPROGRESSDLG
    34.         End If
    35.     End With
    36.     RetCode = SHFileOperation(FileOperation)
    37.     If RetCode <> 0 Then
    38.         TrashFile = False
    39.     Else
    40.         TrashFile = True
    41.     End If
    42.     Exit Function
    43. WhackItError:
    44.     TrashFile = False
    45.     MsgBox Err & " " & Error
    46. End Function
    47.  
    48. Private Sub Command1_Click()
    49. 'to delete it entirely, as with Kill
    50. TrashFile "c:\baby.txt", WhackIt
    51. 'or to send it to the recycle bin
    52. TrashFile "c:\baby.txt", SendToRecycle
    53. 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.

  9. #9
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Lol

    You call that a bit more code?

    1 line,

    8712638971236 lines....

    Hehehe... Anyways, could be useful, I'll check that out, thx!

  10. #10
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    It may seem like a bit more, but it really wont make any difference in terms of speed or size.

  11. #11
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160
    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.

  12. #12
    Addicted Member Stephenb's Avatar
    Join Date
    Nov 2000
    Location
    Phoenix, Arizona.
    Posts
    172
    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.

  13. #13
    Addicted Member
    Join Date
    Apr 2002
    Location
    Anywhere but here
    Posts
    161
    Tag - Cool Function
    -------------------------
    My name says it all!

  14. #14
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    -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:
    1. Private Enum WhatDoIDoWithIt
    2.     SendToRecycle = 1
    3.     WhackIt = 2
    4. End Enum


  15. #15
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702

    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

  16. #16

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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!

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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....
    VB Code:
    1. Dim Bulb as Boolean

    It was before we enacted strict standards here and such things have never been cleaned up....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    Addicted Member Stephenb's Avatar
    Join Date
    Nov 2000
    Location
    Phoenix, Arizona.
    Posts
    172
    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.

  20. #20
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by Stephenb
    But I understood his code just fine.
    And that's the most importaint part here....

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  21. #21
    Addicted Member Stephenb's Avatar
    Join Date
    Nov 2000
    Location
    Phoenix, Arizona.
    Posts
    172
    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
  •  



Click Here to Expand Forum to Full Width