Results 1 to 7 of 7

Thread: Deleting all files in a folder [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349

    Deleting all files in a folder [RESOLVED]

    Hi Guys,
    I want to delete the contents of a directory and i don't really know how to go about doing that. The directory may or may not contain files and it will contain an unknown number of files.

    Any help would be greatly appreciated.
    Last edited by Blinky Bill; Oct 24th, 2002 at 07:14 PM.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. On Error Resume Next
    2.  
    3.     Kill "C:\SomeDir\*.*"

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Lively Member Harvester's Avatar
    Join Date
    May 2002
    Location
    God's Country
    Posts
    124

    File System Object

    The FileSystemObject would be the easiest way although it will require a reference to the scrrun.dll.


    VB Code:
    1. Private Sub KillFiles()
    2. Dim fso as FileSystemObject
    3. Dim myFolder as Folder
    4. Dim myFile as File
    5.  
    6.     Set fso = new FileSystemObject
    7.     Set myFolder = fso.GetFolder(<FolderPath Here>)
    8.  
    9.     For Each myFile in myFolder.Files
    10.         myFile.Delete(True)
    11.     Next myFile
    12.  
    13.  
    14. End Sub

    try that out..

  4. #4

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Thanks crptcblade. Too simple a solution to have occured to me.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If you want another piece of code:
    VB Code:
    1. Shell "Kill C:\SomeDir\*.*"
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Sastraxi, Isn't that pretty much the same code crptcblade posted?
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeh, but meh. Just stating that you can still use the commandline, even though it's Windows
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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