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. General Programming
  3. C#
  4. How to delete a file that is used

How to delete a file that is used

Scheduled Pinned Locked Moved C#
questiontutorial
13 Posts 4 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.
  • O Ollie1986

    There are all created with: new DirectoryInfo(Path.GetDirectoryName(path)).Create(); StreamWriter writer = new StreamWriter(path); writer.WriteLine(content); writer.Close(); But than the locks are fine. But after all the files are created I zip them with "SharpZipLib" and is places locks that last realy long... thx

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #4

    Then there's a bug in the zip library, or in how you're using it.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

    O 2 Replies Last reply
    0
    • C Christian Graus

      Then there's a bug in the zip library, or in how you're using it.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      O Offline
      O Offline
      Ollie1986
      wrote on last edited by
      #5

      I don't think so everything is closed: using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Diagnostics; using System.Threading; using log4net; using ICSharpCode.SharpZipLib.Zip; using System.Collections; using System.Collections.Specialized; namespace InterfaceCollector.domain.DAL { class Zip { private string destination; private readonly ILog log = LogManager.GetLogger(typeof(Zip)); static Hashtable excludeDirs = new Hashtable(); static string startFolder = String.Empty; static string outputZipPath = String.Empty; static string password = String.Empty; public Zip() {} static private Zip instance = null; static public Zip Instance { get { if (instance == null) instance = new Zip(); return instance; } } public void ZipIt(string Path,string password) { log4net.LogManager.Shutdown(); try { ArrayList ar = GenerateFileList(Path); // generate file list // find number of chars to remove from orginal file path int TrimLength = (Directory.GetParent(Path)).ToString().Length; TrimLength += 1; //remove '\' FileStream ostream = null; byte[] obuffer; ZipOutputStream oZipStream = new ZipOutputStream(System.IO.File.Create(Destination)); // create zip stream if (password != String.Empty) oZipStream.Password = password; oZipStream.SetLevel(9); // 9 = maximum compression level ZipEntry oZipEntry; DateTime timeStap = DateTime.Now; string output = ""; int lenghtWrittenString = 0; double percent = 1; int countFiles = 0; foreach (string Fil in ar) // for each file, generate a zipentry { countFiles++; percent = countFiles * 100 / ar.Count; //Display % on progressScreen if (timeStap <= DateTime.Now) { timeStap = DateTime.Now.AddMilliseconds(1000); ApplicationDirector.Instance.removeCharachtersFromProgressScreen(lenghtWrittenString); if (percent < 10

      1 Reply Last reply
      0
      • C Christian Graus

        Then there's a bug in the zip library, or in how you're using it.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        O Offline
        O Offline
        Ollie1986
        wrote on last edited by
        #6

        But you have to know, he releases the locks It just takes to long :(

        C 1 Reply Last reply
        0
        • O Ollie1986

          But you have to know, he releases the locks It just takes to long :(

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #7

          That means, something is NOT closed, but it is eventually garbage collected.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          O 1 Reply Last reply
          0
          • C Christian Graus

            That means, something is NOT closed, but it is eventually garbage collected.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            O Offline
            O Offline
            Ollie1986
            wrote on last edited by
            #8

            that works thx! GC.Collect(); GC.WaitForPendingFinalizers();

            C 1 Reply Last reply
            0
            • O Ollie1986

              that works thx! GC.Collect(); GC.WaitForPendingFinalizers();

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #9

              That's a hack. You should instead figure out what's going wrong with the zip library.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              O 1 Reply Last reply
              0
              • C Christian Graus

                That's a hack. You should instead figure out what's going wrong with the zip library.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                O Offline
                O Offline
                Ollie1986
                wrote on last edited by
                #10

                If we have time at the end :->

                C 1 Reply Last reply
                0
                • O Ollie1986

                  If we have time at the end :->

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #11

                  Well, I'd think if it's a problem in the framework, then others will have encountered it. If you find nothing on google, it's a bug in your code. 'If we have time at the end', means, we're going to leave it broken. At least, that's what I'd expect it to mean.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

                  1 Reply Last reply
                  0
                  • O Ollie1986

                    hey, When I'm trying to delete one of my created files. My program saids it is in use (by himself) but that's because the program is to fast. When I let him wait 10sec the lock is gone... But that not zo good if you have to delete 20-50 files. How can I unlock them automatically? Thx!!!

                    V Offline
                    V Offline
                    Vasudevan Deepak Kumar
                    wrote on last edited by
                    #12

                    In the TaskManager Extension application, there is a way to force close handle. If we can have that done, the problem is solved. TaskManager Extension at: http://www.codeproject.com/system/Task_Manager_Extension.asp[^]

                    Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                    O 1 Reply Last reply
                    0
                    • V Vasudevan Deepak Kumar

                      In the TaskManager Extension application, there is a way to force close handle. If we can have that done, the problem is solved. TaskManager Extension at: http://www.codeproject.com/system/Task_Manager_Extension.asp[^]

                      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                      O Offline
                      O Offline
                      Ollie1986
                      wrote on last edited by
                      #13

                      What do you mean with that?

                      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