Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't find namespace for FileSystemEntry. Who can do me a favor?
C#
using System;
using System.IO;
using System.Security;
namespace DosAPI1
{
	class MyExplorer
	{
		public static void Main(string[] args)
		{
			MyExplorer oExplorer=new MyExplorer();
			string Command;
			string[] CommandLineArgs;
			int ArgumentLength;
			bool CanExit=false;
			Console.WriteLine("Welcome to the MyExplorer Dos Utility");
			do
			{
				Console.Write("MyExplorer>");
				Command=Console.ReadLine ();
				Command=ToSingleSpace(Command.Trim().ToLower());
				CommandLineArgs=oExplorer.ParseCommand(Command.ToLower(),out ArgumentLength);
				switch(CommandLineArgs[0])
				{
					case"cpy":
						if(ArgumentLength!=2)
						{
							ShowError("Usage cpy<source><dest>");
						}
						else
						{
							oExplorer.Copy(CommandLineArgs[1],CommandLineArgs[2]);
						}
						break;
					case"rem":
						if(ArgumentLength!=1)
						{
							ShowError("Usage rem<filename>");
						}
						else
						{
							oExplorer.Remove(CommandLineArgs[1]);
						}
						break;
					case"dir":
					case"ls":
					      switch(ArgumentLength)
					         {
							  case 0:
								  oExplorer.ListFiles(".");
								  break;
							  case 1:
								  oExplorer.ListFiles(CommandLineArgs[1]);
							      break;
							  default:
								  ShowError("Usage dir[<path>]");
								  break;
					         }
						break;
					case "help":
					case "h":
						oExplorer.ShowHelp();
						break;
					case "quit":
					case "exit":
					case "bye":
						CanExit = true;
					  break;
					default:
						 ShowError("Invalid Command");
						break;
				}
			}while(!CanExit);
		}
		public static void ShowError(string StrError)
		{
			Console.WriteLine(StrError);
		}
		public static string ToSingleSpace(string StrToReplace)
		{
			int Position;
			Position=StrToReplace.IndexOf(" ");
			if(Position==-1)
			  return StrToReplace;
			else 
			  return ToSingleSpace(StrToReplace.Substring(0,Position)+StrToReplace.Substring(Position+1));
        }
		public string[] ParseCommand(string Command,out int ArgumentLength)
		{
			string[] CommandLineArgs=Command.Split(new char[]{' '});
			ArgumentLength=CommandLineArgs.Length-1;
            return CommandLineArgs;
		}
		/* Function to the Usage of MyExplorer*/
		public void ShowHelp()
		{
			Console.WriteLine("MyExplorer Help Contents");
			Console.WriteLine("-------------------------");
			Console.WriteLine("cpy<source><dest>-Copies the content of source to dest");
            Console.WriteLine("rem<filename>    -Filename to be deleted");
			Console.WriteLine("dir/ls[<path>]   -Directory Listing");
			Console.WriteLine("h/help           -Help for using MyExplorer");
			Console.WriteLine("quit/exit/bye    -Exit MyExplorer");
		}
		/* Method to perform File Copy operation*/
		public void Copy(string SourceFile,string DestinationFile)
		{
			try
			{
				File.Copy(SourceFile,DestinationFile,true);
				Console.WriteLine("File Copied Successfully");
			}
			catch(FileNotFoundException)
			{
				Console.WriteLine("Source File does not Exists");
			}
			catch(ArgumentException)
			{
				Console.WriteLine("Invalid Argument for cpy");
			}
			catch(SecurityException)
			{
				Console.WriteLine("Write Access is Denied");
			}
			catch(Exception)
			{
				Console.WriteLine("UnKnown Exception");
			}
		}
		/* Function to Delete the Specified File*/
		public void Remove(string FileToRemove)
		{
			try
			{
				File.Delete(FileToRemove);
				Console.WriteLine("File Removed Successfully");
			}
			catch(DirectoryNotFoundException)
			{
				Console.WriteLine("File does not exists");
			}
			catch(SecurityException)
			{
				Console.WriteLine("Delete Permission Denied");
			}
			catch(AccessException)
			{
				Console.WriteLine("Directory name is specified where file is required");
			}
			catch(Exception)
			{
				Console.WriteLine("UnKnown Exception");
			}
		}
        /* Directory Listing*/
		public void ListFiles(string StrDirectoryToList)
		{
            Directory oDir;
			FileSystemEntry[] oFiles;
			try
			{   
				oDir=new Directory(StrDirectoryToList);
				oFiles=oDir.GetFileSystemEntries();
				bool IsFileFound = true;
				foreach(FileSystemEntry f in oFiles)
				{
					if(IsFileFound)
					{
						Console.WriteLine("{0,-32}{1,8}{2}","Name","Size","Directory/File");
						Console.WriteLine(new string('=',80));
							IsFileFound=false;
					}
					if(f.IsFile)
					{
						Console.WriteLine("{0,-32}{1,8}{2}",f.Name,((File)f).Length,"F");
					}
					else 
					{
						Console.WriteLine("{0,-32}{1,8}{2}",f.Name,"0","F");
					}
				}
				
				
			}
			catch(DirectoryNotFoundException)
			{
				Console.WriteLine("Directory Not Found");
			}
			catch(Exception)
			{
			}
		}
	}
}
Posted
Updated 1-Jun-10 23:39pm
v2
Comments
Sandeep Mewara 2-Jun-10 5:40am    
pre locks are your friends for formatting the code while posting... use them!

FileSystemEntry class is not present in the .net API.

In your case following statement returns an array of string not the array of FileSystemEntry class


oFiles = oDir.GetFileSystemEntries();


So in your code instead of using

FileSystemEntry[] oFiles;


You should be using

string[] oFiles;
 
Share this answer
 
v2
Comments
Andyliqinzhang 2-Jun-10 20:41pm    
Thanks a lot.
It does not seems a .NET class. Rather it seems a Dundas API class.

Check here

http://support.dundas.com/public/Dashboard/2_0/Client/(S(unl3yu45iabwyhfsx0w4zx45))/html/T_Dundas_Dashboard_Framework_FileSystem_FileSystemEntry.htm

Otherwise, follow what prakash has suggested. That should be fine too.
 
Share this answer
 
Comments
Andyliqinzhang 2-Jun-10 20:36pm    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900