I want to use CMD command in c# winforms to create a folder to a DIR, with a given directory path,
e.g.
“C:\temp> MD MyFolder”
I wonder how can i execute it using c# win forms platform. I tried looking at google but couldn’t find anything, and is it a good practise to use it, the only reason i wanna use it beacause my directory path is too long for Directory.CreateDirectory() method.
I worked out that CMD have the same limitations as “CreateDirectory” method in C#.
Thanks for your comment and answers people.
All these answers about
Process.Startare wonderful, but I am afraid that we are before yet one more case of an OP asking us to help them implement the solution which they think is going to do what they are trying to achieve instead of asking us how to achieve what they are really trying to achieve.Luckily, the OP has included enough information so that we can guess what they are trying to achieve and give them an answer which might actually be useful to them.
So:
My very first recommendation would be that you fix your directory path so that it is not too long for the
Directory.CreateDirectory()method, because that’s insane, and it is bound to sooner or later cause you problems that you are going to bitterly regret for.If you insist on creating your directory someplace close to the root, use the very fine
System.IO.Path.Combine()method, to build the full path to your directory, so that you can callDirectory.CreateDirectory(), instead of trying to create it from within the current directory in which your application is running, or coming up with bizarre ideas about launching a command processor to create your directory for you.Also, please forget about DOS. These commands have been called
console commandsfor the last 18 years, ever since the release of Windows NT 3.1 back in 1993.