I was just wondering when you have for example:
var dir = new DirectoryInfo(@"C:\Temp");
Is there an easier/clearer way to add a new file to that directory than this?
var file = new FileInfo(Path.Combine(dir.FullName, "file.ext"));
I’m thinking I can probably just make an extension method or something, but curious if something already exists that can’t see here… I mean the DirectoryInfo does have GetFiles() method for example.
What is it that you want to do? The title says “Creating a new file”. A FileInfo object is not a file; it’s an object holding information about a file (that may or may not exist). If you actually want to create the file, there are a number of ways of doing so. One of the simplest ways would be this:
If you want to create the file based on the
FileInfoobject instead, you can use the following approach:As a side note: it is
dir.FullName, notdir.FullPath.