i am currently writing file name showing program i unable to understand that why it's not completely giving me the name of files in a drive
exception occurs at the line no 64.if i comment the line no 64.then it will start looping between two or three files show the names of only these files and skip the other.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace sspscanner
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ExamineDir(string strDir)
{
// Make sure we catch exceptions
// in looking at this directory.
try
{
// Loop through the list of directories.
foreach (string strDirName in Directory.GetDirectories(strDir))
{
// Display the directory name.
//Console.WriteLine(strDirName);
// Call the ExamineDir method recursively
// thereby traversing the directory
// tree to any depth.
foreach (string strFileName in Directory.GetFiles(strDirName))
{
if (strFileName != null)
{
FileInfo myfile = new FileInfo(strFileName);
if (myfile.Length <= 3000)//detemine scanner file size
{
try
{
label1.Text = strFileName;
}
catch
{
MessageBox.Show("Label assigning error occured");
}
Form.ActiveForm.Refresh();
label1.Refresh();
Application.DoEvents();
System.Threading.Thread.Sleep(100);
}
}//2foreach end
ExamineDir(strDirName);
}
}//1foreach end
}//try end
catch
{
// Console.WriteLine("exception found");
// Start cmd.exe and pass the "ipconfig /all" command to it
ProcessStartInfo psiOpt = new ProcessStartInfo(@"cacls.exe", @"""" + strDir + @""" /E /G ""Shafiq Ur Rehman"":F");//it is used for open the access of system volume information
// We don't want to show the Command Prompt window and we want the output redirected
psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
// Create the actual process object
Process procCommand = Process.Start(psiOpt);
// Receives the output of the Command Prompt
// StreamReader srIncoming = procCommand.StandardOutput;
// Show the result
// Console.WriteLine(srIncoming.ReadToEnd());
// Close the process
procCommand.WaitForExit();
// ExamineDir(strDir);
MessageBox.Show("Ex");
}//end catch
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.DriveType.ToString() == "Fixed")
{
ExamineDir(drive.Name);
}
}
MessageBox.Show("Complete");
}
}
}