1

I have added the reference "Microsoft Scripting Runtime", and I have declared :

using Scripting;

Then, I am trying to test it, I made a function :

private void showmessage(string path)
{
FileSystemObject fso;
label1.Text = fso.GetFileName(path); 
}

I am only testing if it works or not, but I got an error "use of an unassigned local variable"

Sorry if it's like silly, and please help me to solve this. God Bless You :)

user1639776
  • 149
  • 2
  • 3
  • 7

2 Answers2

3

You need to initialize FileSystemObject before using it.

Try

FileSystemObject fso = new FileSystemObject();
Erre Efe
  • 15,387
  • 10
  • 45
  • 77
0

Try this instead

label1.Text = System.IO.Path.GetFileName(path)

In .NET you access the file system using the System.IO namespace.

Kane
  • 16,471
  • 11
  • 61
  • 86
  • except you would like to calculate the size of a folder (FAST) https://stackoverflow.com/a/12665904/1498669 – Bernhard Jan 09 '18 at 13:14