A
A
AnimeScotch2021-12-30 09:51:55
Programming
AnimeScotch, 2021-12-30 09:51:55

How to create and on what to make a system for sorting files by type?

I need to create a system that would work on the principle that I put a file of type 1 in a folder, it went to folder 1, I put type 2, it went to 2, and so on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2021-12-30
@AnimeScotch

Absolutely stupid code, works both in Linux and in windows net core 3.1 and higher.
Change OnChanged the full file name arrives there, add your logic.

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace watcher
{
    internal class Program
    {
       
        private static string _exePath;
        private static int Main(string[] args)
        {
            if (args.Length < 2) return ShowHelp();
            var watchFolder = args[0];
            _exePath = args[1];
            var watcher = new FileSystemWatcher
            {
                Path = watchFolder,
                Filter = "*.*",
                IncludeSubdirectories = true,
                NotifyFilter = NotifyFilters.LastAccess |
                               NotifyFilters.LastWrite |
                               NotifyFilters.FileName |
                               NotifyFilters.DirectoryName,
                EnableRaisingEvents = true
            };
            watcher.Created += OnChanged;

            while (true)
            {
                Thread.Sleep(1000);
            }
        }

        private static int ShowHelp()
        {
            Console.WriteLine("usage: watcher path_to_watch_folder path_to_executable");
            return -1;
        }

        private static void OnChanged(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath);
            Process.Start(_exePath, e.FullPath);
        }
    }
}

C
calculator212, 2021-12-30
@calculator212

Yes, you can write on anything. But if you are asking such a question, then you should write it in python, not c++.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question