0

My required commandline is as follow:

sortfolder.exe -6.70_Extensions -7

where 7 is in foreach(var file in files.OrderByDescending(x=>x).Skip(7))

and -6.70_Extensions is in var di = new DirectoryInfo("C:\\Work\\6.70_Extensions\\Build"); and static string path = "C:\\Work\\6.70_Extensions\\Build\\"

sortfolder.exe:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace sortfolder
{
    class Program
    {
        static string path = "C:\\Work\\6.70_Extensions\\Build\\";

        static void Main(string[] args)
        {
            var di = new DirectoryInfo("C:\\Work\\6.70_Extensions\\Build");

            foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
                file.Attributes &= ~FileAttributes.ReadOnly;

            var files = Directory.GetDirectories(path, "SASE Lab Tools.*");
            foreach(var file in files)
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip(7))
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip(7))
            Directory.Delete(file, true);
        }
    }
}

so my commandline is something of the form of: sortfolder.exe -version -integer

and this version could be of any form:

6.70_Extensions
6.80_Extensions
7.00_Main
7.20_Main
8.00_Extensions
etc

and integer

can be any integer

how can i achieve this?

EDIT:

after browsing through this

i edited my code:

namespace sortfolder
{
    class Program
    {
        static void Main(string[] args)
        {
            var di = new DirectoryInfo("C:\\Work\\{0}\\Build", args[0]);
            string path = ("C:\\Work\\{0}\\Build\\", args[0]) ;
            foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
                file.Attributes &= ~FileAttributes.ReadOnly;

            var files = Directory.GetDirectories(path, "SASE Lab Tools.*");
            foreach(var file in files)
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip({0}), args[1])
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip({0}), args[1])
            Directory.Delete(file, true);
        }
    }
}

something is not right in my syntax??

1 Answer 1

3

See the string[] args in Main()? Make use of it.

http://msdn.microsoft.com/en-us/library/acy3edy3.aspx

The above link has all the explanations and examples to get you going.

1
  • As a hint, args[0] will be -6.70_Extensions
    – debracey
    Commented May 24, 2011 at 2:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.