Beispiel #1
0
        /// <summary>
        /// FindFile : locate a specific file and optionally prints search progress on the console
        /// </summary>
        /// <param name="source"> Source media : dvd, network drive, etc</param>
        /// <param name="sFile"> File to search, default = *</param>
        /// <param name="bPrintProgress">Display progress on the console, default is no</param>
        /// <returns> string array including all paths where the file was found</returns>
        public static string[] FindFile(SourceRechercheEnum source, string sFile = "*", bool bPrintProgress = false)
        {
            DriveInfo[] drv = null;
            string[]    allDrivesResults = null;

            if (source == SourceRechercheEnum.CurrentDrive)
            {
                DriveInfo di = new DriveInfo(Environment.CurrentDirectory[0] + ":\\");
                return(ParcoureArborescence(di.RootDirectory, sFile, bPrintProgress));
            }

            drv = DriveInfo.GetDrives();

            foreach (DriveInfo d in drv)
            {
                string[] partialDrives = null;
                switch (d.DriveType)
                {
                case DriveType.CDRom:
                    if (d.IsReady && (source == SourceRechercheEnum.AllRemovable ||
                                      source == SourceRechercheEnum.AllRemovableAndNetworked ||
                                      source >= SourceRechercheEnum.AllFixedAndRemovable))
                    {
                        partialDrives = ParcoureArborescence(d.RootDirectory, sFile, bPrintProgress);
                        if (partialDrives == null || partialDrives[0] == "EXCEPTION")
                        {
                            return(partialDrives);
                        }
                        allDrivesResults = buildReturnArray(partialDrives, allDrivesResults);
                    }
                    break;

                case DriveType.Fixed:
                    if (d.IsReady && (source == SourceRechercheEnum.AllFixed ||
                                      source == SourceRechercheEnum.AllFixedAndNetworked ||
                                      source == SourceRechercheEnum.AllFixedAndRemovable ||
                                      source == SourceRechercheEnum.AllDrives))
                    {
                        partialDrives = ParcoureArborescence(d.RootDirectory, sFile, bPrintProgress);
                        if (partialDrives == null || partialDrives[0] == "EXCEPTION")
                        {
                            return(partialDrives);
                        }
                        allDrivesResults = buildReturnArray(partialDrives, allDrivesResults);
                    }
                    break;

                case DriveType.Network:
                    if (d.IsReady && (source == SourceRechercheEnum.AllFixedAndNetworked ||
                                      source == SourceRechercheEnum.AllNetworked ||
                                      source >= SourceRechercheEnum.AllRemovableAndNetworked))
                    {
                        partialDrives = ParcoureArborescence(d.RootDirectory, sFile, bPrintProgress);
                        if (partialDrives == null || partialDrives[0] == "EXCEPTION")
                        {
                            return(partialDrives);
                        }
                        allDrivesResults = buildReturnArray(partialDrives, allDrivesResults);
                    }
                    break;

                case DriveType.Removable:
                    if (d.IsReady && (source == SourceRechercheEnum.AllRemovable ||
                                      source >= SourceRechercheEnum.AllFixedAndRemovable))
                    {
                        partialDrives = ParcoureArborescence(d.RootDirectory, sFile, bPrintProgress);
                        if (partialDrives == null || partialDrives[0] == "EXCEPTION")
                        {
                            return(partialDrives);
                        }
                        allDrivesResults = buildReturnArray(partialDrives, allDrivesResults);
                    }
                    break;
                }
            }
            return(allDrivesResults);
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("ff v1 -- Écrit par J.F.Gratton, 2011");
            Console.ForegroundColor = ConsoleColor.White;

            if (args.Length < 2 || args[0].ToLower() == "/h" || args[0].ToLower() == "-h" ||
                args[0] == "/?" || args[1] == "-?")
            {
                Help();
            }

            string[]            sFichiersTrouves = null;
            string              sFichier         = args[1];
            bool                bPrintDirs       = false;
            SourceRechercheEnum source           = SourceRechercheEnum.None;

            if (args[args.Length - 1].ToLower() == "-print")
            {
                bPrintDirs = true;
            }

            switch (args[0].ToLower())
            {
            case "-cdrv":
                source = SourceRechercheEnum.CurrentDrive;
                break;

            case "-arem":
                source = SourceRechercheEnum.AllRemovable;
                break;

            case "-afix":
                source = SourceRechercheEnum.AllFixed;
                break;

            case "-afxr":
                source = SourceRechercheEnum.AllFixedAndRemovable;
                break;

            case "-anet":
                source = SourceRechercheEnum.AllNetworked;
                break;

            case "-afxn":
                source = SourceRechercheEnum.AllFixedAndNetworked;
                break;

            case "-armn":
                source = SourceRechercheEnum.AllRemovableAndNetworked;
                break;

            case "-all":
                source = SourceRechercheEnum.AllDrives;
                break;

            default:
                Help();
                break;
            }
            if (source != SourceRechercheEnum.None)
            {
                sFichiersTrouves = FileUtils.FindFile(source, sFichier, bPrintDirs);
            }

            if (sFichiersTrouves != null)
            {
                Array.Sort(sFichiersTrouves);
                foreach (string fichier in sFichiersTrouves)
                {
                    Console.WriteLine(fichier);
                }
            }
        }