Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. How to delete multiple files using FSO and wildcards...

How to delete multiple files using FSO and wildcards...

Scheduled Pinned Locked Moved Web Development
sysadmintutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Garth
    wrote on last edited by
    #1

    I am trying to use the file system object to delete a batch of files, based on the name of the file. E.g. I have files in the format: file17_68.asp The first number signifies a category, the second is an individual ID. What I want to be able to do is delete files that belong to the one category. What I've tried is: *start code snippet* set fso = Server.Createobject("Scripting.FileSystemObject") fname = "\files\file" & EditCatID & "*.asp" fso.DeleteFile(Server.MapPath(fname)) set fso = nothing **end code snippet** I thought the wildcard (*) would mean that all files beginning file17 would then be successfully deleted. This fails to work - so does anyone have any brilliant and cunning ideas? or suggestions why this doesn't work?

    P 1 Reply Last reply
    0
    • G Garth

      I am trying to use the file system object to delete a batch of files, based on the name of the file. E.g. I have files in the format: file17_68.asp The first number signifies a category, the second is an individual ID. What I want to be able to do is delete files that belong to the one category. What I've tried is: *start code snippet* set fso = Server.Createobject("Scripting.FileSystemObject") fname = "\files\file" & EditCatID & "*.asp" fso.DeleteFile(Server.MapPath(fname)) set fso = nothing **end code snippet** I thought the wildcard (*) would mean that all files beginning file17 would then be successfully deleted. This fails to work - so does anyone have any brilliant and cunning ideas? or suggestions why this doesn't work?

      P Offline
      P Offline
      Philip Patrick
      wrote on last edited by
      #2

      It works fine, but MapPath cannot map file names with wildcards. You need to map the directory first and then add a file name, like this:

      set fso = Server.Createobject("Scripting.FileSystemObject")
      fso.DeleteFile Server.MapPath("\files\") & "\file" & EditCatID & "*.asp"
      set fso = nothing

      Philip Patrick Web-site: www.saintopatrick.com "Two beer or not two beer?" Shakesbeer Need ASP hosting? Check out 123HostNow.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups