A small list of file classes in a folder
Using system;
Namespace codebuilder. Builder
{
Class mainclass
{
Public static void main (string [] ARGs)
{
// For (INT f = 0; F <4; F ++)
//{
Int F = 3;
System. Console. writeline ("_______________ {begin }_______________");
String folder = system. Console. Readline ();
Filefilter filter = new filterfactory (). createinstance (f );
Listfolder = new listfolder (folder, filter );
System. Collections. arraylist Al = listfolder. files;
If (Al! = NULL)
{
For (int I = 0; I <al. Count; I ++)
{
System. Console. WriteLine ("_____ {0} _____", I );
System. Console. WriteLine (al [I]);
}
}
System. Console. WriteLine ("_______________ {End }_______________");
System. Console. ReadLine ();
//}
}
}
Public class FilterFactory
{
Public FileFilter CreateInstance (int I)
{
Switch (I)
{
Case 0:
Return new wfilter ();
Case 1:
Return new xfilter ();
Case 2:
Return new yfilter ();
Case 3:
Return new zfilter ();
Default:
Return new filefilter ();
}
}
Public filefilter createinstance (string Str)
{
Switch (STR)
{
Case ". CS ":
Return new WFilter ();
Case ". aspx ":
Return new XFilter ();
Case ". aspx. cs ":
Return new YFilter ();
Case ". xml ":
Return new ZFilter ();
Default:
Return new FileFilter ();
}
}
}
Public class ZFilter: FileFilter
{
Public override bool Filter (string filename)
{
Return filename. ToLower (). EndsWith (". xml ");
}
}
Public class YFilter: FileFilter
{
Public override bool Filter (string filename)
{
Return filename. ToLower (). EndsWith (". aspx. cs ");
}
}
Public class XFilter: FileFilter
{
Public override bool Filter (string filename)
{
Return filename. ToLower (). EndsWith (". aspx ");
}
}
Public class WFilter: FileFilter
{
Public override bool Filter (string filename)
{
Return filename. ToLower (). EndsWith (". cs ");
}
}
Public class filefilter
{
Public Virtual bool filter (string filename)
{
Return true;
}
}
Public sealed class listfolder
{
System. Collections. arraylist _ FILES = new system. Collections. arraylist ();
Filefilter;
Public listfolder (string path, filefilter filter)
{
This. filefilter = filter;
Folder (PATH );
}
Public System. Collections. arraylist files
{
Get {return _ Files ;}
}
Void Folder (string path)
{
If (System. IO. File. Exists (path ))
{
Docase (path );
}
Else if (System. IO. Directory. Exists (path ))
{
String [] files = new string [0];
Files = System. IO. Directory. GetFiles (path );
For (int I = 0; I <files. Length; I ++)
{
Docase (files [I]);
}
String [] folders = System. IO. Directory. GetDirectories (path );
For (int I = 0; I <folders. Length; I ++)
{
Folder (folders [I]);
}
}
}
Void docase (string path)
{
If (filefilter. Filter (path) _ Files. Add (path );
}
}
}