deleting *.doc in asp.net

Discussion in 'ASP .Net' started by Stimp, Nov 20, 2005.

  1. Stimp

    Stimp Guest

    I want to delete all my .doc files in a specific directory.

    I tried to do this using the File.Delete method, but it doesn't allow
    "*.doc" paths.

    So I tried the following code:

    Dim objFSO = Server.CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile(Server.MapPath("*.doc"))

    and it works on my local pc, but I doubt I should be using classic asp
    components with asp.net.. what was is the equivalent function in
    asp.net?

    Cheers.
    --

    fiddlewidawiddum
    Stimp, Nov 20, 2005
    #1
    1. Advertising

  2. off the top of my head try something like this :

    DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
    FileInfo[] docfiles = dir.GetFiles("*.doc");

    Foreach( FileInfo f in docfiles)
    {
    File.Delete( f.Name)
    }

    --
    Regards

    John Timney
    ASP.NET MVP
    Microsoft Regional Director

    "Stimp" <> wrote in message
    news:...
    >I want to delete all my .doc files in a specific directory.
    >
    > I tried to do this using the File.Delete method, but it doesn't allow
    > "*.doc" paths.
    >
    > So I tried the following code:
    >
    > Dim objFSO = Server.CreateObject("Scripting.FileSystemObject")
    > objFSO.DeleteFile(Server.MapPath("*.doc"))
    >
    > and it works on my local pc, but I doubt I should be using classic asp
    > components with asp.net.. what was is the equivalent function in
    > asp.net?
    >
    > Cheers.
    > --
    >
    > fiddlewidawiddum
    John Timney \( MVP \), Nov 20, 2005
    #2
    1. Advertising

  3. Stimp

    Stimp Guest

    On Sun, 20 Nov 2005 John Timney ( MVP ) <> wrote:
    > off the top of my head try something like this :
    >
    > DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
    > FileInfo[] docfiles = dir.GetFiles("*.doc");
    >
    > Foreach( FileInfo f in docfiles)
    > {
    > File.Delete( f.Name)
    > }


    nope doesn't seem to work.

    Dim dir As DirectoryInfo = New
    DirectoryInfo(Server.MapPath("mydirectory"))

    Dim docfiles() As FileInfo = dir.GetFiles("*.doc")

    Dim f As FileInfo

    For Each f In docfiles
    File.Delete(f.Name)
    Next

    --

    fiddlewidawiddum
    Stimp, Nov 20, 2005
    #3
  4. Stimp

    Stimp Guest

    On Sun, 20 Nov 2005 John Timney ( MVP ) <> wrote:
    > off the top of my head try something like this :
    >
    > DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
    > FileInfo[] docfiles = dir.GetFiles("*.doc");
    >
    > Foreach( FileInfo f in docfiles)
    > {
    > File.Delete( f.Name)
    > }


    actually I just got it working... the problem was with the path used in
    the File.Delete section

    Thanks!
    --

    fiddlewidawiddum
    Stimp, Nov 20, 2005
    #4
  5. Sorry - as I said off the top of my head. Glad to have helped.

    --
    Regards

    John Timney
    ASP.NET MVP
    Microsoft Regional Director

    "Stimp" <> wrote in message
    news:...
    > On Sun, 20 Nov 2005 John Timney ( MVP ) <> wrote:
    >> off the top of my head try something like this :
    >>
    >> DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
    >> FileInfo[] docfiles = dir.GetFiles("*.doc");
    >>
    >> Foreach( FileInfo f in docfiles)
    >> {
    >> File.Delete( f.Name)
    >> }

    >
    > actually I just got it working... the problem was with the path used in
    > the File.Delete section
    >
    > Thanks!
    > --
    >
    > fiddlewidawiddum
    John Timney \( MVP \), Nov 20, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wallace
    Replies:
    0
    Views:
    466
    John Wallace
    Jul 22, 2003
  2. Matt
    Replies:
    3
    Views:
    497
    Tor Iver Wilhelmsen
    Sep 17, 2004
  3. Praveen Chhangani

    Converting a org.jdom DOC to org.w3c DOC

    Praveen Chhangani, Aug 5, 2003, in forum: XML
    Replies:
    2
    Views:
    962
    Johannes Koch
    Aug 7, 2003
  4. Harry Barker
    Replies:
    2
    Views:
    513
    Alf P. Steinbach
    Apr 19, 2006
  5. crea
    Replies:
    2
    Views:
    407
    Nobody
    Dec 28, 2012
Loading...

Share This Page