S
Sirin Azazi
Hi,
I wrote simple program to get the .c and .h files in a folder and number of
lines they contain. It works; but when i choose the 'c:\' folder, i get an
Argument Exception.
when i choose another driver or folder, there is no error. what could be the
reason? if the reason is hidden system files which is being used by System,
is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)"
block);
for (int i = 0; i < files.Length; i++)
{
if ((files.Substring(files.Length - 2) == ".c") ||
(files.Substring(files.Length - 2) == ".C")
|| (files.Substring(files.Length - 2) == ".h") ||
(files.Substring(files.Length - 2) == ".H"))
{
FileStream fs = new FileStream(files,FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files = files.Substring(fpath.Length);
if (files.StartsWith("\\")) files = files.Substring(1);
newrow = new string[]{ files,(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows.HeaderCell.Value = i.ToString();
}
}
I wrote simple program to get the .c and .h files in a folder and number of
lines they contain. It works; but when i choose the 'c:\' folder, i get an
Argument Exception.
when i choose another driver or folder, there is no error. what could be the
reason? if the reason is hidden system files which is being used by System,
is there a way to access files (for reading) as they are being used?
that is a part of the program (it's in a "try-catch(ArgumentException)"
block);
for (int i = 0; i < files.Length; i++)
{
if ((files.Substring(files.Length - 2) == ".c") ||
(files.Substring(files.Length - 2) == ".C")
|| (files.Substring(files.Length - 2) == ".h") ||
(files.Substring(files.Length - 2) == ".H"))
{
FileStream fs = new FileStream(files,FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
str = reader.ReadToEnd();
int count = 0;
for (int k = 0; k < str.Length; k++)
{
if (str[k] == '\n')
count++;
}
reader.Close();
fs.Close();
fs.Dispose();
files = files.Substring(fpath.Length);
if (files.StartsWith("\\")) files = files.Substring(1);
newrow = new string[]{ files,(count+1).ToString() ,null };
dataGridView1.Rows.Add(newrow);
dataGridView1.Rows.HeaderCell.Value = i.ToString();
}
}