I added an alternative code-path using an input string rather than reading from a file.
I would require an empty FileInfo object as I have many instances which access the Name
, Length
and Extension
property.
Ideally I am looking for something like
FileInfo _fileinfo = new FileInfo(File.Empty);
However there is only one FileInfo
constructor, which appears to require a valid file. Any solution to creating an empty-initialized FileInfo object, which does not require the creation of an empty dummy file?
I just came across a similar problem. What do you think about starting with:
FileInfo _fileinfo = null;
After that, you could just do:
_fileinfo = new FileInfo(<string of file with path>);
You would then have an object that you could pass as parameter to your methods. Don't foget to check if your object is null before you try to get the values for .Name and so on
if(null != _fileinfo)
{
//some code
}
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