Advertisement
kyrathasoft

cull.cs

Jun 9th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using com.wms.dirs;
  5. using com.wms.files;
  6.  
  7. /*
  8.     You'll first need to compile dirs.dll from com_wms_dirs.cs. That source code is found
  9.     in c:\csdev\library\dirs_dll\, or at these URLs:
  10.             + https://gist.github.com/kyrathasoft/aca4a458ce58edb05f4476a8186cae33
  11.             + https://pastebin.com/C42PBvgM
  12.     To compile dirs.dll use: csc /t:library /out:dirs.dll com_wms_dirs.cs
  13.     Then, to compile the cull.cs source code file, which should be in the same
  14.     directory as dirs.dll, use: csc /r:dirs.dll cull.cs
  15.    
  16.     To merge files.dll, dirs.dll, and cull.exe: ilmerge /t:exe cull.exe dirs.dll files.dll /ndebug /out:excull.exe
  17.    
  18. */
  19.  
  20. namespace ConsoleApplication {
  21.  
  22.     class Program
  23.     {
  24.         public static string PathC = @"c:\\csdev\\examples";
  25.         public static string PathE = @"e:\\csdev\\examples";
  26.        
  27.         static void Main(string[] args)
  28.         {
  29.             Console.ForegroundColor = ConsoleColor.Yellow;
  30.             Console.WriteLine("\n cull.exe");
  31.             Console.ForegroundColor = ConsoleColor.White;            
  32.            
  33.             string the_path = PathC;
  34.             if(!Directory.Exists(the_path)){ the_path = PathE; }
  35.            
  36.             if(!Directory.Exists(the_path)){
  37.                 Console.WriteLine(" Fatal problem: couldn't locate directory c:\\csdev\\examples!");
  38.                 return;
  39.             }
  40.            
  41.             string path_mod = the_path.Replace(@"\\", @"\");
  42.             Console.WriteLine(" for culling DLL libraries and executables recursively from {0}", path_mod);            
  43.                        
  44.             try{
  45.                 int example_subdirs = Directory.GetDirectories(the_path, "*", SearchOption.TopDirectoryOnly).Length;
  46.                 Console.WriteLine(" Subdirectories found in {0}: {1}", path_mod, example_subdirs);
  47.                 int total_files = ClassDirs.GetDirectoryFileCount(the_path);
  48.                 Console.WriteLine(" Total files across examples (all directory levels): {0}", total_files);
  49.                 if(example_subdirs > 0){
  50.                     List<string> subdirs = ClassDirs.GetListOfSubdirectoryPaths(the_path);
  51.                     int deleted_executables = ClassFiles.DeleteAllFilesWithGivenExtension(subdirs, ".exe");
  52.                     int deleted_pdb = ClassFiles.DeleteAllFilesWithGivenExtension(subdirs, ".pdb");
  53.                     int deleted_partials = ClassFiles.DeleteAllFilesWithGivenExtension(subdirs, ".partial");
  54.                     int deleted_dlls = ClassFiles.DeleteAllFilesWithGivenExtension(subdirs, ".dll");
  55.                     Console.WriteLine(" *.exe files found and deleted: {0}", deleted_executables);
  56.                     Console.WriteLine(" *.pdb files found and deleted: {0}", deleted_pdb);
  57.                     Console.WriteLine(" *.partial files found and deleted: {0}", deleted_partials);
  58.                     Console.WriteLine(" *.dll files found and deleted: {0}", deleted_dlls);
  59.                 }
  60.             }catch{}
  61.         }  
  62.        
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement