namespace ProcessSWFile
{
class Program
{
static void Main(string[] args)
{
...
string dir = args[0];
try
{
foreach (string f in Directory.GetFiles(@dir, "*.out"))
{
...
}
catch
{
Console.WriteLine("Directory {0} \n could not be accessed!", dir);
return;
}
ProcessSWFile f:\dir1
Directory f:\dir1
could not be accessed!
while the folder does exist there. why?
fs = new FileStream(@fld1, FileMode.CreateNew);here you want to create a new file or directory in a try block without a catch block. if the statement throws an exception it would jump into the catch where the 'could not accessed' was shown. the fld1 is only filled for some conditions which I can't verify that they were true. so in my opinion, the CreateNew will fail (and possibly throw an exception) if you pass fld1 is an empty string or if the fld1 contains the name of an existing directory.
try
{
foreach (string f in Directory.GetFiles(dir, "*.out"))
{
...
as it now only processes 1st file. why?
catch
{
Console.WriteLine("Directory {0} \n could not be accessed!", dir);
return;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
Try running this app as administrator and see what happens in that case.