I want to create a file that is in specific directory. For example: C:\x\y\z\aTextFile.txt
For this operation, I have to create the directory to create file.
Directory.CreateDirectory(@"C:\x\y\z\");
File.Create(@"C:\x\y\z\aTextFile.txt");
But I really wonder that I can do this operation in single line of code.
Any help and idea will be greately appreciated.
Simple: Add a function
void MySingleLineOfCodeFunction(string path, string filename)
{
Directory.Createdirectory(path);
File.Create(filename).Dispose();
}
and then use a single line of code:
MySingleLineOfCodeFunction(@"C:\x\y\z\", "a.txt");
What I am trying to say is that there is no difference between code. Some of it is written by the Microsoft guys, while other by us, normal people. But the computers don't make a difference. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With