Advertisement
konalisp

ls.exe

Sep 5th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. //
  2. //    Copyright 2014 Chauncey
  3. //    
  4. //    This program is free software: you can redistribute it and/or modify
  5. //    it under the terms of the GNU Lesser General Public License as published
  6. //    by the Free Software Foundation, either version 3 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU Lesser General Public License for more details.
  13. //    
  14. //    You should have received a copy of the GNU Lesser General Public License
  15. //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. //    
  17. //    
  18. //    
  19. //    
  20.  
  21. using System;
  22. using System.IO;
  23. using System.Collections.Generic;
  24.  
  25. //todo: add formatting/flags
  26.  
  27. public class LS {
  28.     static public int Main (string[] args) {
  29.         string path = @"";
  30.         if (args.Length == 0) {
  31.             path = Directory.GetCurrentDirectory();
  32.         }
  33.         else if (args[0] == "--help") {
  34.             //Console.WriteLine(help);
  35.         }
  36.         else {
  37.             path = args[0];
  38.         }
  39.        
  40.         //WriteOut("\n");
  41.         WriteOut(".  ");
  42.         WriteOut("..  ");
  43.        
  44.         getdir(path);
  45.         WriteOut("\n");
  46.        
  47.         return 0;
  48.     }
  49.    
  50.     public static string reverses (string a) {
  51.         char[] input = a.ToCharArray();
  52.         Array.Reverse(input);
  53.         return new string(input);
  54.     }
  55.    
  56.     static public void WriteOut (string a) {
  57.         Console.Write(a); //make this format stuff
  58.     }
  59.    
  60.     static public int getdir (string path) {
  61.         string slash = (System.Environment.OSVersion.Platform == PlatformID.Win32NT) ? "\\" : "/";
  62.        
  63.         string[] fdir = Directory.GetFiles(path);
  64.         string[] ddir = Directory.GetDirectories(path);
  65.        
  66.         List<string> list = new List<string>();
  67.         list.AddRange(fdir);
  68.         list.AddRange(ddir);
  69.         string[] dir = list.ToArray();
  70.        
  71.         foreach (string key in dir) {
  72.             string input = key;
  73.             int index = input.LastIndexOf(slash);
  74.             if (index != -1) {
  75.                 input = input.Substring(index+1);
  76.             }
  77.             WriteOut(input + "  ");
  78.         }
  79.         return 0;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement