Revision: 77127
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 23, 2019 03:10 by martinbrait
Initial Code
// For Directory.GetFiles and Directory.GetDirectories // For File.Exists, Directory.Exists using System; using System.IO; using System.Collections; public class RecursiveFileProcessor { public static void Main(string[] args) { System.Console.WriteLine("parameter count = {0}", args.Length); if (Directory.Exists(args[0])) { // This path is a directory Console.WriteLine("Il y a {0} repertoires dans {1}.", ProcessDirectory(args[0]), args[0]); } else { Console.WriteLine("{0} is not a valid directory.", args[0]); } } // Process all directories // that are found, and process the files they contain. public static int ProcessDirectory(string targetDirectory) { int resultat = 0; // Recurse into subdirectories of this directory. string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory); foreach(string subdirectory in subdirectoryEntries) // pour chaque sous répertoire resultat = resultat + 1 + ProcessDirectory(subdirectory); // on compte le répertoire actuel au quel on ajoute le nombre de sous-dossiers return resultat; } }
Initial URL
Initial Description
count the folders and subfolders of a directory
Initial Title
[c#] [directory] compter les dossiers et les sous-dossiers d'un répertoire
Initial Tags
files, directory
Initial Language
C#