Effect of using FileInfo this way?

  • Thread starter Thread starter Michael A. Covington
  • Start date Start date
M

Michael A. Covington

I just saw something like this in someone else's code and am curious...


string fname;

.... store a filename in fn ...

FileInfo fi = new FileInfo(fname);
string name = fi.Name;


What is the difference between fname and name? By creating FileInfo do we
verify that the file exists? Retrieve its full path? Or what?
 
fname is a full path name, but Name just is a file name which doesn't
contain path but contain extension.

For second, we can verify that file exists according to FileInfo class'
Exists property.
Such as,

FileInfo fi = new FileInfo(fname);
if (fi.Exists)
{
// do other things
}

Sincerely,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top