Beispiel #1
0
        //Method to enumerates files then retrieve file info for those files
        private static List <SimpleFileInfo> GetFileData(List <string> exceptions, List <string> copyDirectories, List <string> wildCards)
        {
            //Instantiate objects for use
            List <SimpleFileInfo> files = new List <SimpleFileInfo>();
            FileInfo fileInfo;

            //Used to calculate bin packing
            //const int bytesPerMb = 1048576;

            //Use SafeFileEnumerator to get files then retrieve file info for those files
            for (int i = 0; i < copyDirectories.Count(); i++)
            {
                foreach (string x in SafeFileEnumerator.EnumerateFiles(copyDirectories[i], "*", SearchOption.AllDirectories).Except(exceptions))
                {
                    try
                    {
                        fileInfo = new FileInfo(x);
                        SimpleFileInfo simpleFileInfo = new SimpleFileInfo
                        {
                            Path   = fileInfo.FullName,
                            SizeMb = (double)Math.Ceiling((decimal)(fileInfo.Length)) // / bytesPerMb))
                        };
                        files.Add(simpleFileInfo);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Log.LogWrite(_exceptionError);
                        Log.LogWrite(ex.Message);
                        Log.LogWrite(ex.Source);
                        continue;
                    }
                }
            }

            if (wildCards != null)
            {
                foreach (string x in wildCards)
                {
                    files.RemoveAll(z => z.Path.EndsWith(x));
                }
            }

            //Sort list by descending to aid in packing
            //return files.OrderByDescending(f => f.SizeMb).ToList();
            return(files.ToList());
        }
Beispiel #2
0
        //Method to enumerates files then retrieve file info for those files
        private static List<SimpleFileInfo> GetFileData(List<string> exceptions, List<string> copyDirectories, List<string> wildCards)
        {
            //Instantiate objects for use
            List<SimpleFileInfo> files = new List<SimpleFileInfo>();
            FileInfo fileInfo;

            //Used to calculate bin packing
            //const int bytesPerMb = 1048576;

            //Use SafeFileEnumerator to get files then retrieve file info for those files
            for (int i = 0; i < copyDirectories.Count(); i++)
            {
                foreach (string x in SafeFileEnumerator.EnumerateFiles(copyDirectories[i], "*", SearchOption.AllDirectories).Except(exceptions))
                {
                    try
                    {

                        fileInfo = new FileInfo(x);
                        SimpleFileInfo simpleFileInfo = new SimpleFileInfo
                        {
                            Path = fileInfo.FullName,
                            SizeMb = (double)Math.Ceiling((decimal)(fileInfo.Length)) // / bytesPerMb))
                        };
                        files.Add(simpleFileInfo);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Log.LogWrite(_exceptionError);
                        Log.LogWrite(ex.Message);
                        Log.LogWrite(ex.Source);
                        continue;
                    }
                }
            }

            if (wildCards != null)
            {
                foreach (string x in wildCards)
                {
                    files.RemoveAll(z => z.Path.EndsWith(x));
                }
            }

            //Sort list by descending to aid in packing
            //return files.OrderByDescending(f => f.SizeMb).ToList();
            return files.ToList();
        }