Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I would like create folder but I want create folder name same as file name.
C:\file.zip - it is file in root on C
C:\file.zip - it is directory in root on C

I want create folder "file.zip" if in same directory exist file "file.zip" with same name.

Thank you

C#
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: Cannot create "C:\file.zip" because a file or directory with the same name already exists.


What I have tried:

If file don't exist so I can create folder.
C#
Directory.CreateDirectory(@"C:\file.zip\");
Posted
Updated 7-Nov-16 21:56pm
Comments
smoula99 8-Nov-16 5:34am    
OK. It is not possible create file and folder with same name.
Thanks for answes

You cannot create a folder if a file with the same name already exists: the system would be confused. And conversely, you can't create a file if a folder with the same name exists. So it refuses to let you for very good reasons.
Would you name all your children the same? Because that would be very confusing when you want one of them to do something!

Don't try to have files and folder with the same name, it's not a good idea at all.
 
Share this answer
 
You can't. The operating system prohibits it.
 
Share this answer
 
You simply cannot do that: Windows doesn't allow that.
 
Share this answer
 

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



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