Hello,
I am working on an application that needs to access a local directory scan it and display the content RootDirectory>SubDirectory type of listing.
I have been trying different codes but not getting any output.
I don't know if i am using the appropriate language or the wrong approach!
Take a look at this code:
Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class DirectoryObject
{
static void Main(string[] args)
{
DirectoryInfo MyRoot = new DirectoryInfo(@"C:\Documents and Settings\My Documents");
DirectoryInfo[] MySub;
DirectoryInfo TheFolder = null;
FileInfo[] MyFiles;
FileInfo TheFile = null;
FileStream MyStream;
MyRoot.CreateSubdirectory("MyFolder");
MySub = MyRoot.GetDirectories();
foreach (DirectoryInfo D in MySub)
{
if (D.Name == "MyFolder")
TheFolder = D;
}
MyFiles = TheFolder.GetFiles();
foreach (FileInfo F in MyFiles)
{
if (F.Name == "Testing.txt")
{
TheFile = F;
MyStream =
TheFile.Open(FileMode.Create,
FileAccess.ReadWrite,
FileShare.ReadWrite);
int i = 0;
byte b = 0;
while (i != 000)
{
MyStream.WriteByte(b); i++; b++;
}
}
}
//TheFile.Delete();
//TheFolder.Delete();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
FileInfo test = new FileInfo(@ "C:\Documents and Settings\My Documents");
Console.WriteLine(test.Exists.ToString());
}
}
}
namespace WindowsFormsApplication1
{
public class Test
{
public static void Main(string [] args)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Documents and Settings\s_sossou\My Documents";
watcher.NotifyFilter =
NotifyFilters.LastAccess|
NotifyFilters.LastWrite|
NotifyFilters.FileName|
NotifyFilters.DirectoryName;
watcher.Filter = "*.txt";
watcher.Changed += new FileSystemEventHandler(Onchanged);
watcher.Created += new FileSystemEventHandler(Onchanged);
watcher.Deleted += new FileSystemEventHandler(Onchanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.EnableRaisingEvents = true;
}
public static void Onchanged(object source,
FileSystemEventArgs e)
{
Console.WriteLine("Event Fired");
}
public static void OnRenamed(object source, RenamedEventArgs e)
{
Console.WriteLine("Event Fired");
}
}
}
public class Test
{
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
Console.WriteLine("Event Fired");
}
}
Thanks in advance,