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. Simple IO Question (or at least I hope so)

Simple IO Question (or at least I hope so)

Scheduled Pinned Locked Moved C#
12 Posts 5 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.
  • L Lost User

    If you want the solution, post the code for your project here. :laugh:

    M Offline
    M Offline
    MNantu
    wrote on last edited by
    #3

    Well, I guess you're right. My bad, my bad. :-O

            DirectoryInfo dir = new DirectoryInfo(srcDirectory);
            
            foreach (FileInfo fil in dir.GetFiles("\*.jpg"))
            {
                imagesJPEG.Add(Bitmap.FromFile(fil.FullName));
                fileNames.Add(fil.Name);
                imageCount++;
            }
            foreach (FileInfo fil in dir.GetFiles("\*.tiff"))
            {
                imagesTIFF.Add(Bitmap.FromFile(fil.FullName));
                fileNames.Add(fil.Name);
                imageCount++;
            }
            foreach (FileInfo fil in dir.GetFiles("\*.png"))
            {
                    imagesPNG.Add(Bitmap.FromFile(fil.FullName));
                    fileNames.Add(fil.Name);
                    imageCount++;
            }
    

    This is the only code which has direct access to directories. All other functions just use a string for the destination folder and doesn't have anything to do with folders =)

    G X 2 Replies Last reply
    0
    • M MNantu

      Well, I guess you're right. My bad, my bad. :-O

              DirectoryInfo dir = new DirectoryInfo(srcDirectory);
              
              foreach (FileInfo fil in dir.GetFiles("\*.jpg"))
              {
                  imagesJPEG.Add(Bitmap.FromFile(fil.FullName));
                  fileNames.Add(fil.Name);
                  imageCount++;
              }
              foreach (FileInfo fil in dir.GetFiles("\*.tiff"))
              {
                  imagesTIFF.Add(Bitmap.FromFile(fil.FullName));
                  fileNames.Add(fil.Name);
                  imageCount++;
              }
              foreach (FileInfo fil in dir.GetFiles("\*.png"))
              {
                      imagesPNG.Add(Bitmap.FromFile(fil.FullName));
                      fileNames.Add(fil.Name);
                      imageCount++;
              }
      

      This is the only code which has direct access to directories. All other functions just use a string for the destination folder and doesn't have anything to do with folders =)

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #4

      If you are working with images, don't forget to dispose them. Otherwise they will stay locked.

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      M 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        If you are working with images, don't forget to dispose them. Otherwise they will stay locked.

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        M Offline
        M Offline
        MNantu
        wrote on last edited by
        #5

        Thanks for the reply They are disposed right after they are processed but I will take a look at that just to make sure. But, as I said, files which are copied into the target directory are not locked. Only the target directory stays locked.

        L 1 Reply Last reply
        0
        • M MNantu

          Thanks for the reply They are disposed right after they are processed but I will take a look at that just to make sure. But, as I said, files which are copied into the target directory are not locked. Only the target directory stays locked.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #6

          Hi, use Image.FromStream() instead of Image.FromFile(); that way they don't get locked at all. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          M 1 Reply Last reply
          0
          • M MNantu

            Well, I guess you're right. My bad, my bad. :-O

                    DirectoryInfo dir = new DirectoryInfo(srcDirectory);
                    
                    foreach (FileInfo fil in dir.GetFiles("\*.jpg"))
                    {
                        imagesJPEG.Add(Bitmap.FromFile(fil.FullName));
                        fileNames.Add(fil.Name);
                        imageCount++;
                    }
                    foreach (FileInfo fil in dir.GetFiles("\*.tiff"))
                    {
                        imagesTIFF.Add(Bitmap.FromFile(fil.FullName));
                        fileNames.Add(fil.Name);
                        imageCount++;
                    }
                    foreach (FileInfo fil in dir.GetFiles("\*.png"))
                    {
                            imagesPNG.Add(Bitmap.FromFile(fil.FullName));
                            fileNames.Add(fil.Name);
                            imageCount++;
                    }
            

            This is the only code which has direct access to directories. All other functions just use a string for the destination folder and doesn't have anything to do with folders =)

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #7

            Bitmap.FromFile() sucks, it keep lock the file until you dispose that Bitmap instance. Use Bitmap.FromStream() instead.

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, use Image.FromStream() instead of Image.FromFile(); that way they don't get locked at all. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


              M Offline
              M Offline
              MNantu
              wrote on last edited by
              #8

              So, you say this can keep only the folder locked, while the files created are not. I'll give it a try and let you know. Thanks =)

              L 1 Reply Last reply
              0
              • M MNantu

                So, you say this can keep only the folder locked, while the files created are not. I'll give it a try and let you know. Thanks =)

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #9

                MNantu wrote:

                So, you say this can keep only the folder locked

                I didn't say a thing about folders. However when a file is locked, so is the entire path to it. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                M L 2 Replies Last reply
                0
                • L Luc Pattyn

                  MNantu wrote:

                  So, you say this can keep only the folder locked

                  I didn't say a thing about folders. However when a file is locked, so is the entire path to it. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                  M Offline
                  M Offline
                  MNantu
                  wrote on last edited by
                  #10

                  Well, actually that's the point which confuses me. =) Files are ok. They can be deleted, renamed, moved, whatever you want. But only the folder is not. You cannot do these to the folder and when you try you face that "File's in use" kinda error =) But as I said just the folder not the entire path. :) Maybe I'm a sinner and God is punishing me this way ;P Seriously, I wonder what I'm doing wrong. :)

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    MNantu wrote:

                    So, you say this can keep only the folder locked

                    I didn't say a thing about folders. However when a file is locked, so is the entire path to it. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #11

                    Hi, if your folder is locked when your app runs,, and not when it doesn't run, then there is something wrong in your app. if your folder is locked all the time, then either some other program is locking it (try closing every app), or it got a read-only flag set. if you need help, provide very specific symptoms. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                    M 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Hi, if your folder is locked when your app runs,, and not when it doesn't run, then there is something wrong in your app. if your folder is locked all the time, then either some other program is locking it (try closing every app), or it got a read-only flag set. if you need help, provide very specific symptoms. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                      M Offline
                      M Offline
                      MNantu
                      wrote on last edited by
                      #12

                      I guess you're right about the details I've provided, my mistake :) And the folder is locked all the time after I've created it (manually created by the way, not created by the application). Anyways I'll have to figure out a solution no matter what. So thanks for the effort, everyone :)

                      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