menu

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

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

1 comment

Command shell script in the sheller.

2 Answers

by
 
Best answer
0 votes
Absolutely dumb code, works in both linux and windows net core 3.1 and higher.
Change OnChanged where the full name of the file arrives, 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);
}
}
}
2 votes
You can write that on anything. But if you ask this question, you should write it in python, not in C++.

2 Comments

A neighboring reply mentions FileSystemWatcher . After all, it was enough to point to the name of the class or function.
And you have to write a program in Python. There is no magic there either.