Delete files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krazitchek

    #1

    Delete files

    Hi, how do i do to delete files with a specific extension
    (like *.lnk).

    I try File.Delete(@"e :\test\\*.lnk) but it does not work,
    not the good way i guess...

    Help please, thanks.
  • gani

    #2
    Re: Delete files

    foreach(string sFile in System.IO.Direc tory.GetFiles(" D:\\"))
    {
    if (sFile.ToUpper( ).EndsWith(".LN K"))

    System.IO.File. Delete(sFile);
    }

    --
    gani




    "Krazitchek " <krazitchek@hot mail.com> wrote in message
    news:028d01c36a d8$8ef22560$a00 1280a@phx.gbl.. .[color=blue]
    > Hi, how do i do to delete files with a specific extension
    > (like *.lnk).
    >
    > I try File.Delete(@"e :\test\\*.lnk) but it does not work,
    > not the good way i guess...
    >
    > Help please, thanks.[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Delete files

      Krazitchek,
      To borrow gani's code:

      foreach(string sFile in System.IO.Direc tory.GetFiles(@ "e:\test\", "*.lnk"))
      {
      System.IO.File. Delete(sFile);
      }

      The Directory.GetFi les function returns a string array of all the files in a
      folder, the method is overloaded for an optional pattern.

      As far as I can tell the array always includes the path passed to GetFiles.

      Hope this helps
      Jay

      "Krazitchek " <krazitchek@hot mail.com> wrote in message
      news:028d01c36a d8$8ef22560$a00 1280a@phx.gbl.. .[color=blue]
      > Hi, how do i do to delete files with a specific extension
      > (like *.lnk).
      >
      > I try File.Delete(@"e :\test\\*.lnk) but it does not work,
      > not the good way i guess...
      >
      > Help please, thanks.[/color]


      Comment

      • Krazitchek

        #4
        Delete files

        Thank you.

        Comment

        Working...