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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help regarding deleting files in a directory

Help regarding deleting files in a directory

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 3 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.
  • A Offline
    A Offline
    anu81
    wrote on last edited by
    #1

    hi all In my application, i have a treeview consisting of some nodes. when i click a node, i am generating some images and displaying them in a listview. i am storing the images temporarily in a folder in the application path. so everytime a node is clicked, i need to remove the original images and add the new images. when i tried to delete the contents of the folder, it says file is in use(which is obvious). Can anybody suggest me ideas as how to remove the old images from the folder?

    Thanks in advance.:) Regards Anuradha

    A 1 Reply Last reply
    0
    • A anu81

      hi all In my application, i have a treeview consisting of some nodes. when i click a node, i am generating some images and displaying them in a listview. i am storing the images temporarily in a folder in the application path. so everytime a node is clicked, i need to remove the original images and add the new images. when i tried to delete the contents of the folder, it says file is in use(which is obvious). Can anybody suggest me ideas as how to remove the old images from the folder?

      Thanks in advance.:) Regards Anuradha

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      You must have forgotten to close the filestream or something. So all you need to do is make sure you Close() all your streams before deleting all your files.

      My current favourite word is: Waffle Cheese is still good though.

      A 1 Reply Last reply
      0
      • A Anthony Mushrow

        You must have forgotten to close the filestream or something. So all you need to do is make sure you Close() all your streams before deleting all your files.

        My current favourite word is: Waffle Cheese is still good though.

        A Offline
        A Offline
        anu81
        wrote on last edited by
        #3

        hi, thanks for your reply. but i am not using filestream class at all. i used the following code. foreach (File file in Directory.GetFiles(path)) { File.Delete(file); }

        Thanks in advance.:) Regards Anuradha

        A 1 Reply Last reply
        0
        • A anu81

          hi, thanks for your reply. but i am not using filestream class at all. i used the following code. foreach (File file in Directory.GetFiles(path)) { File.Delete(file); }

          Thanks in advance.:) Regards Anuradha

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #4

          "i am storing the images temporarily in a folder in the application path" Does that not mean that your creating a new files, and writing to them during runtime? Because if it does, once youve written the file, you need to close the stream. If the files are already there, then unless you've got them open somewhere, or explorer has them open. They should just delete fine. If its the latter, go download 'unlocker' and see whats holding your files hostage.

          My current favourite word is: Waffle Cheese is still good though.

          A 1 Reply Last reply
          0
          • A Anthony Mushrow

            "i am storing the images temporarily in a folder in the application path" Does that not mean that your creating a new files, and writing to them during runtime? Because if it does, once youve written the file, you need to close the stream. If the files are already there, then unless you've got them open somewhere, or explorer has them open. They should just delete fine. If its the latter, go download 'unlocker' and see whats holding your files hostage.

            My current favourite word is: Waffle Cheese is still good though.

            A Offline
            A Offline
            Aavesh Agarwal
            wrote on last edited by
            #5

            i think u shuld check the permission of the Folder in which u are storing ur image file.Give the permission of write also. May be it will work for you. or i m not getting ur question Thanks and Regards Aavesh Agarwal

            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