Click here to Skip to main content
15,867,991 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Every one...
My problem is that I want to delete a file from one folder.Originally the size of the file is 0 byte. but in my code it shows 27 bytes(by this code File_name.Length ). that's why i can not delete that file.
what is reason behind it ? and how can i delete that one?

Thanking You
Posted
Comments
Karthik Harve 11-Sep-12 4:55am    
Can you paste your code where you are deleting the file ?
krushna chandra jena 11-Sep-12 6:41am    
Actually I want to delete empty folders. That's why here i try to check any folder contains any file or not. and if it contains empty file then the folder will be deleted. and my code is string Spath2=Spath +@"\"+fj; // Spath is a directory path and fj is the name of my textfile if (Spath2.Length== 0) //Here it shows Length=27 { Directory.Delete( Spath, true); } but my textfile does not contain any data,thats why it shows 0 byte when i check it manually by mouse click .but in my code it shows 27 bytes when i Debug it. Why it shows Length is 27?
[no name] 11-Sep-12 5:02am    
Hi,

File size is 0 byte.
27, is actually length of the file name (File_name.Length). Your file name is 27 characters long.

Are you facing any exception or what's the actual issue you're facing when you run your code?

Please share the code which is not (supposedly) working.
krushna chandra jena 11-Sep-12 7:05am    
No i didn't get any exception ...
Actually I want to delete empty folders. That's why here i try to check any folder contains any file or not. and if it contains empty file then the folder will be deleted. and my code is
string Spath2=Spath +@"\"+fj;
// Spath is a directory path and fj is the name of my textfile
if (Spath2.Length== 0) //Here it shows Length=27
{
Directory.Delete ( Spath, true);
}
but my textfile does not contain any data,thats why it shows 0 byte when i check it manually by mouse click .but in my code it shows 27 bytes when i Debug it. Why it shows Length is 27?
Mohamed Mitwalli 11-Sep-12 5:18am    
Share your code .

System.IO.File.Delete(File_name);
that's the command, not File_name.Delete() or something like that...
 
Share this answer
 
Hi Krushna,

Your code is perfect, except for this if condition:

VB
if (Spath2.Length== 0)


You are checking the length of Spath2 string here. It is 27 characters in length.

Again I repeat. 27 is not the file size, it is the number of alphabets/characters in the string Spath2.

To check for the file size, you have to do something like this.

VB
 string Spath2=Spath +@"\"+fj;   
FileInfo objFileInfo=new FileInfo(Spath2);
if (objFileInfo.Size == 0)


Check and let me know.
 
Share this answer
 
v2
Comments
Kuthuparakkal 11-Sep-12 7:17am    
my 5+
krushna chandra jena 11-Sep-12 7:50am    
Yes its done ....
Thanks a lot........
Thank You Very much once again.....
[no name] 11-Sep-12 7:52am    
Welcome Krushna, Do accept the answer if it helped.
File size is now 0byte. its sisz must be 27bytes..could be please explain a bit more. you have to delete it through code?
 
Share this answer
 
Comments
krushna chandra jena 11-Sep-12 6:40am    
Actually I want to delete empty folders.
That's why here i try to check any folder contains any file or not.
and if it contains empty file then the folder will be deleted.
and my code is


string Spath2=Spath +@"\"+fj;
// Spath is a directory path and fj is the name of my textfile
if (Spath2.Length== 0) //Here it shows Length=27
{
Directory.Delete( Spath, true);
}
but my textfile does not contain any data,thats why it shows 0 byte when i check it manually by mouse click .but in my code it shows 27 bytes when i Debug it.

Why it shows Length is 27?
Kuthuparakkal 11-Sep-12 7:18am    
Ask for clarity thru comments/questions and do not use Answer portion. Voting this down.100-

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900