|
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.
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.
|
|
|
|
|
If you want the solution, post the code for your project here.
|
|
|
|
|
Well, I guess you're right. My bad, my bad.
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.
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
Seriously, I wonder what I'm doing wrong.
|
|
|
|
|
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
|
|
|
|
|
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi guys,
I've written a simple C# console application is VS.NET 2005 and now I want that as soon as the user clicks on the exe file, the location of the exe file, no matter wherever it is, is shifted to 'D:/Folder/'. It is noteworthy, that I dont want replication, just replacement of the original exe file from its source location, to that location programmed. Therefore, can anyone help me with that little piece of code, using which I can replace my console app. from its current location to another location programatically allocated on the system?
Your help will be appreciated,
Rajdeep.NET
|
|
|
|
|
|
thanx! U see, nobody helps me in CodeProject! I dont know why. They say I post wrong answers! But thats no problem. I give right answers or wrong or whatever, but atleast, I am answering.
|
|
|
|
|
Oh, come on!
I think you need a hug
Happy to help you out.
|
|
|
|
|
In which type of application, you can use such type of implementation?
|
|
|
|
|
Hello Rajdeep,
It is possible.You should copy your exe to another location and then pass the aregument to that exe to delete first.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
I can probably think that you are trying to make some malicious applications....
Anyway! Here we go...
Long time back i read this article....
Load an EXE File and Run It from Memory[^]
Here goes the hypothesis of Julien:
Load the exe file and inside the exe, write a file delete or move operation.
After this, you may quit the exe which may get what you required....
Never tried this... but you may give a try and send me a feedback.....
Jai Ho........
Have a Happy Coding.....
|
|
|
|
|
I am trying to make a windows application where i want to play a videos in the form.
How can i load videos to the form
Please Help.....
|
|
|
|
|
Thats not possible in Windows Form, u can try that in Web Applications.
|
|
|
|
|
You're wrong on so many levels that it's almost - well - funny.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Stop giving wrong directions to people....
Think of how would you feel, if you get same kinda reply from people when you post questions.....
Have a Happy Coding.....
|
|
|
|
|
Julien, u commented on me something like this:
//Stop giving wrong directions to people....
//Think of how would you feel, if you get same kinda reply from people //when you post questions.....
Look, till now, I did not get any correct or appropriate suggestion from any of you. If you are so much caring for other queries, then why do u left those posted by me 'BLANK'?????
|
|
|
|
|
Rajdeep.NET wrote: then why do u left those posted by me 'BLANK'?????
That must be probably the funniest thing i heard....
RajDeep, who ever posting replies here, are spending their spare time, and sharing their knowledge out of their own interest....
They dont work for anybody and they are not under compulsion, that every question here is to be answered.....
Take a look at all your previous posts....
Almost every question is answered.....
You might had some bad experience here but showing the same thing to others is not appreciable.....
Cheers.......
Have a Happy Coding.....
|
|
|
|