Pages

Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Friday, January 2, 2009

Processes with C#

Something that's not of much interest to me right now. I knew about it but never found any application so I never used it.


Process graph= new Process();
graph.StartInfo.FileName = "C:\\Program
Files\\Graph\\Graph.exe";
//graph.StartInfo.Arguments = "any
arugment";
graph.Start();


Starts Graph process. With additional properties, you can set it to run in the background.


Process[] processlist = Process.GetProcesses();
foreach (Process theprocess
in processlist)
{
Console.WriteLine("Process: {0} ID: {1}",
theprocess.ProcessName, theprocess.Id);
}

This gets all the processes and displays some information about them.

See the documentation for more information. It's pretty simple and there isn't anything interesting in my opionion. Threads are bit more interesting ...

Thursday, January 1, 2009

Merging several files in different directories under one single directory

I had many directories under one directory with some files in each of them and I wanted to merge all the files together in a single directory. I created following C# file in a console application that has a _MoveFiles static method which peforms all the work.

Example Usage:

class Program
{
static void Main(string[] args)
{
string[] notToInclude = { "C:\\Program Files\\abc" };
MoveFiles._MoveFiles("C:\\Program Files\\abc",
"C:\\Program Files\\abc_target",
notToInclude,
null,
null,
false);
}
}

You can pass several criteria to define which directories to choose and which to ignore and which file extensions should be picked. And, if in the end the program should attempt to delete the directory (only possible if the directory gets empty).

MoveFiles

It can be further imporved but I have finished my work :)