PoshCode Archive  Artifact [2221eec54c]

Artifact 2221eec54cda505ecb9cf28ab8beafb844b34a48dc40995da5bf2c9a3734cebb:

  • File WhatIs.ps1 — part of check-in [dc05543776] at 2018-06-10 13:42:18 on branch trunk — UNIX which and whatis tools analog. (user: greg zakharov size: 1231)

# encoding: ascii
# api: csharp
# title: WhatIs
# description: UNIX which and whatis tools analog.
# version: 0.1
# type: class
# author: greg zakharov
# license: CC0
# x-poshcode-id: 4515
# x-archived: 2013-10-16T20:22:58
# x-published: 2013-10-10T16:45:00
#
#
using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Globalization;

[assembly: AssemblyVersion("2.0.0.0")]

namespace WhatIsTool {
  internal sealed class Program {
    static string[] SplitVariable(string eVar) {
      return Environment.ExpandEnvironmentVariables(eVar).Split(new Char[] {';'});
    }
    
    static void Main(string[] args) {
      string query, desc;
      
      if (args.Length == 1) {
        foreach (string path in SplitVariable("%PATH%")) {
          foreach (string ext in SplitVariable("%PATHEXT%")) {
            query = path + @"\" + args[0] + ext.ToLower(CultureInfo.CurrentCulture);
            if (File.Exists(query)) {
              desc = FileVersionInfo.GetVersionInfo(query).FileDescription;
              Console.WriteLine("{0} - {1}", query, String.IsNullOrEmpty(desc) ? "n/a" : desc);
            }
          }
        }
      }
    }
  }
}