Simple IO Question (or at least I hope so)
-
Hi All, I have a question that I can't answer, I hope you guys will help me =) I have a program in which user selects a source directory and a target directory and the files in the source directory are processed and copied into the target directory. All is fine until this: I created directories manually (for test purposes), I mean not inside the code but Right Click-->New-->New Folder =) When the process is done, files are OK. This means they can be deleted, moved, renamed. But the directories stay locked. I cannot rename, move, delete the directories. :doh: So, why does this happen and how can I correct it? Thanks :) Edit: Oh, by the way I forgot to mention I used DirectoryInfo and FileInfo.
-
Hi All, I have a question that I can't answer, I hope you guys will help me =) I have a program in which user selects a source directory and a target directory and the files in the source directory are processed and copied into the target directory. All is fine until this: I created directories manually (for test purposes), I mean not inside the code but Right Click-->New-->New Folder =) When the process is done, files are OK. This means they can be deleted, moved, renamed. But the directories stay locked. I cannot rename, move, delete the directories. :doh: So, why does this happen and how can I correct it? Thanks :) Edit: Oh, by the way I forgot to mention I used DirectoryInfo and FileInfo.
-
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 =)
-
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 =)
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
-
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
-
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.
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
-
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 =)
Bitmap.FromFile()
sucks, it keep lock the file until you dispose thatBitmap
instance. UseBitmap.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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
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
-
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 =)
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
-
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
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. :)
-
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
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
-
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
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 :)