Guest User

Untitled

a guest
Nov 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace Filmsammler
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         private string path;
  16.         private DirectoryInfo[] pathdirinfo;        
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.         private void m_btn_start_Click(object sender, EventArgs e)
  22.         {
  23.             DialogResult result = m_fb_dialog.ShowDialog();
  24.             path  = m_fb_dialog.SelectedPath;
  25.             string[] paths = GetAllFolderNamesAsString(GetAllFolders(path));
  26.             string filename = path + "output.txt";
  27.             Clipboard.SetText(tofilestring(GetAllFolderNamesAsString(GetAllFolders(path)))+filelisttooutputstring(GetFileList(path,false)));
  28.            
  29.         }
  30.         private void CollectFilms()
  31.         {
  32.            
  33.         }
  34.         public string filelisttooutputstring(List<string> files)
  35.         {
  36.             string outputstring = "";
  37.             foreach (var file in files)
  38.             {
  39.                 outputstring += file + "\n";
  40.             }
  41.             return outputstring;
  42.         }
  43.         public List<string> GetFileList(string Root, bool SubFolders)
  44.         {
  45.             List<string> FileArray = new List<string>();
  46.             try
  47.             {
  48.                 string[] Files = System.IO.Directory.GetFiles(Root);
  49.                 string[] Folders = System.IO.Directory.GetDirectories(Root);
  50.  
  51.                 for (int i = 0; i < Files.Length; i++)
  52.                 {
  53.                     FileArray.Add(Files[i].ToString());
  54.                 }
  55.  
  56.                 if (SubFolders == true)
  57.                 {
  58.                     for (int i = 0; i < Folders.Length; i++)
  59.                     {
  60.                         FileArray.AddRange(GetFileList(Folders[i], SubFolders));
  61.                     }
  62.                 }
  63.             }
  64.             catch (Exception Ex)
  65.             {
  66.                 throw (Ex);
  67.             }
  68.             return FileArray;
  69.         }
  70.         public DirectoryInfo GetFolderInformation(string sFolder)
  71.         {
  72.         DirectoryInfo m_dir;
  73.         m_dir = new DirectoryInfo(sFolder);
  74.             return m_dir;
  75.         }
  76.         public DirectoryInfo[] GetAllFolders(string sFolder)
  77.         {
  78.             DirectoryInfo[] folders;
  79.             folders = new DirectoryInfo(path).GetDirectories();
  80.             return folders;
  81.         }
  82.         private string[] GetAllFolderNamesAsString(DirectoryInfo[] dirinfos)
  83.         {
  84.             string[] name = new string[999];
  85.             string[] cleanname;
  86.             int count = 0;
  87.             foreach (var directoryInfo in dirinfos)
  88.             {
  89.                 name[count] = directoryInfo.Name.ToString();
  90.                 count++;
  91.             }
  92.             cleanname = new string[count];
  93.             for (int i = 0; i < count; i++)
  94.             {
  95.                 cleanname[i] = name[i];
  96.             }
  97.             return cleanname;
  98.         }
  99.         private string tofilestring(string[] names)
  100.         {
  101.             string outputstring = "";
  102.             foreach (string name in names)
  103.             {
  104.                 outputstring += name + "\n";
  105.             }
  106.             return outputstring;
  107.         }
  108.  
  109.     }
  110. }
Add Comment
Please, Sign In to add comment