Skip to main content

Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Here is the COBOL equivalent:

      $set ilusing"System"
      $set ilusing"System.IO"
      $set ilusing"System.Security.Permissions"
       class-id Watcher.Watcher.
       working-storage section.
       method-id Main public static.
       local-storage section.
       procedure division.
           invoke self::Run
           goback.
       end method.

       method-id #Run public static
       attribute PermissionSet(type SecurityAction::Demand, property Name="FullTrust").
       local-storage section.
       01 any-key  pic x value spaces.
       procedure division.
           
           declare args as string occurs any = type System.Environment::GetCommandLineArgs

        *> If a directory is not specified, exit program.
           if args::Length not = 2
            *> Display the proper way to call the program.
              display "Usage: Watcher.exe (directory)"
              goback
           end-if
        
        *> Create a new FileSystemWatcher and set its properties.
           declare watcher as type FileSystemWatcher = new FileSystemWatcher
           set watcher::Path to args[1]
        *> Watch for changes in LastAccess and LastWrite times, and
        *> the renaming of files or directories. 
           set watcher::NotifyFilter to type NotifyFilters::LastAccess b-or type NotifyFilters::LastWrite
           b-or type NotifyFilters::FileName b-or type NotifyFilters::DirectoryName
        *> Only watch text files.
           set watcher::Filter to "*.txt"

        *> Add event handlers.
           attach method OnChanged as type FileSystemEventHandler to watcher::Changed
           attach method OnChanged as type FileSystemEventHandler to watcher::Created
           attach method OnChanged as type FileSystemEventHandler to watcher::Deleted
           attach method OnRenamed as type RenamedEventHandler to watcher::Renamed
        *> Begin watching.
           set watcher::EnableRaisingEvents to true
      
        *> Wait for the user to quit the program.
           display "Press 'q' to quit the sample."
           perform until exit
              accept any-key
              if function upper-case(any-key) = "Q"
                 exit perform
              end-if
           end-perform
      
           exit method
       end method.
       *> Define the event handlers.
       method-id OnChanged private static.
       procedure division using by value #source as object, e as type FileSystemEventArgs.
        *> Specify what is done when a file is changed, created, or deleted.
           display "File: " &  e::FullPath & " " & e::ChangeType
           goback.
       end method.
       method-id OnRenamed private static.
       procedure division using by value #source as object, e as type RenamedEventArgs.
        *> Specify what is done when a file is renamed.
           display "File: " & e::OldFullPath & " renamed to " & e::FullPath
           goback.
       end method.
       end class.

Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Thanks, helped a lot, but if I need to set a folder (directory), as could be done, already much but thank you. Always remembering that the translation is Google


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

     declare watcher as type FileSystemWatcher = new FileSystemWatcher("C:\\temp", "*.txt")

I could do with that came a fixed folder, but can not convert to windows form you could help me, thank you.  


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

I think you would have to set those properties in the constructor as follows::

declare watcher as type FileSystemWatcher = new FileSystemWatcher(property Path="C:\\temp", property Filter="*.txt")


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Thanks, tried to convert to form windows but I can not.


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

So you wish to have this functionality in a Windows Forms project is that correct? If you want this monitoring to be done in the background you will have to make this multithreaded by creating Worker thread, etc.

I could probably whip up a sample here that started the monitor thread and ran it until a button on the form was clicked. Is that what you are looking for?


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Chris, thank you for help, that's exactly what I need, this process will run and when new files in the folder it shows to the user that there are new things for him there.


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

I have found a pretty good demo in C# and have rewritten it in Visual COBOL. I have published a new KB article here that has the demo attached to it.

Please give it a try and let me know if this is what you were looking for,

Thanks


Need to convert this program in C# for Cobol can anyone help me to understand what I need is to make a routine that it is reading a particular folder and when you input files it shows me, this routine found on the Microsoft website.
thanks, sorry for the English, translated by Google.

using System;
using System.IO;
using System.Security.Permissions;

public class Watcher
{

    public static void Main()
    {
    Run();

    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        string[] args = System.Environment.GetCommandLineArgs();

        // If a directory is not specified, exit program.
        if(args.Length != 2)
        {
            // Display the proper way to call the program.
            Console.WriteLine("Usage: Watcher.exe (directory)");
            return;
        }

        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = args[1];
        /* Watch for changes in LastAccess and LastWrite times, and
           the renaming of files or directories. */
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        // Only watch text files.
        watcher.Filter = "*.txt";

        // Add event handlers.
        watcher.Changed = new FileSystemEventHandler(OnChanged);
        watcher.Created = new FileSystemEventHandler(OnChanged);
        watcher.Deleted = new FileSystemEventHandler(OnChanged);
        watcher.Renamed = new RenamedEventHandler(OnRenamed);

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press \\'q\\' to quit the sample.");
        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: "   e.FullPath " " e.ChangeType);
    }

    private static void OnRenamed(object source, RenamedEventArgs e)
    {
        // Specify what is done when a file is renamed.
        Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
    }
}

Perfect, that's what I needed, but thank you very much.