public static void RemoveEmptyDirs(string parent_dir) { foreach (string dir in Directory.GetDirectories(parent_dir)) { RemoveEmptyDirs(dir); } if (Directory.GetFileSystemEntries(parent_dir).Length == 0) { MyDirectory.RemoveRecursively(parent_dir); } }
async private void Convert() { await Task.Run(() => { statusBar.Text = "Getting list of mod files..."; string[] mod_files = MyDirectory.GetRelativeFileNames(tbModPath.Text); statusBar.Text = "Getting list of game files..."; string[] game_files = MyDirectory.GetRelativeFileNames(tbGamePath.Text); if (Directory.Exists(tbOutputPath.Text)) { statusBar.Text = "Removing output directory..."; MyDirectory.RemoveRecursively(tbOutputPath.Text); } foreach (string file in mod_files) { statusBar.Text = "Copying mod files... (" + file + ")"; string output = Path.Combine(tbOutputPath.Text, file); Directory.CreateDirectory(Path.GetDirectoryName(output)); File.Copy(Path.Combine(tbModPath.Text, file), output, true); File.SetAttributes(output, FileAttributes.Normal); } foreach (string folder in Directory.GetDirectories(tbModPath.Text)) { string ffolder = Path.GetFileName(folder); UnpackFiles(ffolder, tbModPath.Text, tbOutputPath.Text, tbGamePath.Text); } statusBar.Text = "Removing temp files..."; MyDirectory.RemoveRecursively(Path.Combine(tbOutputPath.Text, "orig")); statusBar.Text = "Removing empty directories..."; MyDirectory.RemoveEmptyDirs(tbOutputPath.Text); statusBar.Text = "Done"; if (tbModPath.InvokeRequired) { tbModPath.Invoke(new MethodInvoker(delegate { //Code goes here MakeUIActive(true); ; })); } MyDirectory.OpenInExplorer(tbOutputPath.Text); }); }
public static void RemoveRecursively(string dir) { foreach (string file in Directory.GetFiles(dir)) { MyFile.Delete(file); } foreach (string dirr in Directory.GetDirectories(dir)) { MyDirectory.RemoveRecursively(dirr); } Directory.Delete(dir); }