当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.GetFiles方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.GetFiles方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetFiles方法的具体用法?C# DirectoryInfo.GetFiles怎么用?C# DirectoryInfo.GetFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.GetFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCalibrationPlateMarkViewModelTest

        public void GetCalibrationPlateMarkViewModelTest(string testCaseDir)
        {
            //assign
            var calc = new CalibImageCalculator();
            var caseDirInfo = new DirectoryInfo(testCaseDir);
            var descFile = caseDirInfo.GetFiles("caltab.descr").SingleOrDefault().FullName;

            var plateParamPath = caseDirInfo.GetFiles("calibParam.xml").SingleOrDefault().FullName;
            var startCamParamPath = caseDirInfo.GetFiles("startCamParam.dat").SingleOrDefault().FullName;
            CalibrationPlateParam plateParam;
            using (FileStream fs = new FileStream(plateParamPath, FileMode.Open))
            {
                XmlSerializer sr = new XmlSerializer(typeof(CalibrationPlateParam));
                plateParam = (CalibrationPlateParam)sr.Deserialize(fs);
            }

            HTuple startCamParam;
            HOperatorSet.ReadCamPar(startCamParamPath, out startCamParam);

            //act
            foreach (FileInfo imgInfo in caseDirInfo.EnumerateFiles(@"calibImages\*.tiff"))
            {
                var img = new HImage(imgInfo.FullName);
                var model = calc.GetCalibrationPlateMarkViewModel(descFile, img, plateParam, startCamParam);

                //assert
                Assert.True(model.Valid);
            }
        }
开发者ID:Joncash,项目名称:CameraCalibration,代码行数:29,代码来源:CalibrationCalculatorTest.cs

示例2: cmdBatch_Click

        private void cmdBatch_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog dlgFolder = new FolderBrowserDialog();

                dlgFolder.Description = "Batch files all image files from this folder.";

                if (dlgFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DirectoryInfo dirInfo = new DirectoryInfo(dlgFolder.SelectedPath.ToString());

                    FileInfo[] ImageFiles = dirInfo.GetFiles("*.jpg").Concat(dirInfo.GetFiles("*.jpeg")).Concat(dirInfo.GetFiles("*.png")).ToArray();

                    for (int i = 0; i < ImageFiles.Length; ++i)
                    {
                        FileInfo ImageFile = ImageFiles[i];
                        Bitmap ImageBitmap = new Bitmap(ImageFile.FullName);

                        ProcessImage(ImageBitmap);
                    }

                    MessageBox.Show("Image Files Process Completed", "Process Completed", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }
开发者ID:Blissgig,项目名称:CaptureCrop,代码行数:30,代码来源:Form1.cs

示例3: GetAllFiles

 private static string[] GetAllFiles(DirectoryInfo directory, string extension)
 {
     List<string> allFiles = new List<string>();
     DirectoryInfo[] allDirectory = directory.GetDirectories();
     if (allDirectory.Length > 0)
     {
         foreach (string[] files in allDirectory.Select(single => GetAllFiles(single, extension)))
         {
             allFiles.AddRange(files);
         }
         FileInfo[] fileInfos = directory.GetFiles();
         allFiles.AddRange(from file in fileInfos
                           where file.Extension.ToLower().Equals(extension)
                           select file.FullName);
         return allFiles.ToArray();
     }
     else
     {
         FileInfo[] files = directory.GetFiles();
         allFiles.AddRange(from file in files
                           where file.Extension.ToLower().Equals(extension)
                           select file.FullName);
         return allFiles.ToArray();
     }
 }
开发者ID:romhackingvn,项目名称:Alpha-Translation,代码行数:25,代码来源:Program.cs

示例4: FMEntityEditor_Load

        private void FMEntityEditor_Load(object sender, EventArgs e)
        {
            txEntityName.Focus();
            DirectoryInfo dir = new DirectoryInfo(Application.StartupPath + "\\att_temps");
            foreach (FileInfo dd in dir.GetFiles())
            {
                cmbTemplate.Items.Add(dd.Name);
            }
            if (dir.GetFiles().Length > 0)
            {
                cmbTemplate.SelectedIndex = 0;
            }
            cmbMySQLDataType.DataSource = Enum.GetValues(typeof(MySqlDbType));

            this.splitContainer3.Panel2Collapsed = true;
            if (entity == null)
            {
                entity = new EntityInfo();
            }
            chkNeedFPYTable.Checked = entity.NeedfpyTable;
            txNotes.Text = entity.Notes;

            BindAttributes();
            BindConstraintAtt();
        }
开发者ID:Dhenskr,项目名称:hoyi-er-tool,代码行数:25,代码来源:FMEntityEditor.cs

示例5: GetFiles

        public List<FileNames> GetFiles()
        {
            List<FileNames> lstFiles = new List<FileNames>();
            var path = HostingEnvironment.MapPath("~/files");
            var dirInfo = new DirectoryInfo(path);
            int i = 0;
            if (dirInfo.GetFiles() != null)
            {
                foreach (var item in dirInfo.GetFiles().OrderBy(u => u.LastWriteTime))
                {

                    lstFiles.Add(new FileNames()
                    {

                        FileId = i + 1,
                        FileName = item.Name,
                        FilePath = dirInfo.FullName + @"\" + item.Name,

                    });
                    i = i + 1;
                }
            }
            else
            {

            }

            return lstFiles;
        }
开发者ID:pureman9,项目名称:Teamduty,代码行数:29,代码来源:DataClass.cs

示例6: FindFileType

 public void FindFileType()
 {
     DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\nkindschi_be\C#\EmailScanner\EmailFolder");
     FileInfo[] files = directoryInfo.GetFiles("*.txt");
     files = directoryInfo.GetFiles("*.csv");
     files = directoryInfo.GetFiles("*.xml");
 }
开发者ID:nealkindschi,项目名称:EmailScanner,代码行数:7,代码来源:EmailFolder.cs

示例7: PlayMusic

        public void PlayMusic(string music, bool isTheme)
        {
            canLoop = isTheme;
            if (isTheme || (player.Source == null && (music == "" || music == "NULL" || music == null)))
            {
                DirectoryInfo soundFilesDir = new DirectoryInfo(AppGlobals.soundDir);
                FileInfo fullPath = soundFilesDir.GetFiles().Where(d => d.Name.ToLower().Contains(AppGlobals.currGlobalAdventure.Theme.ToLower())).OrderBy(x => rnd.Next()).First();

                player.Open(new Uri(@fullPath.FullName, UriKind.Relative));
                player.MediaEnded += MediaPlayer_Loop;
                player.Play();
                
            }
            else if (player.Source == null && (music != "" || music != "NULL" || music != null))
            {
                DirectoryInfo soundFilesDir = new DirectoryInfo(AppGlobals.soundDir);
                var gg = soundFilesDir.GetFiles();
                FileInfo fullPath = soundFilesDir.GetFiles().Where(d => d.Name.ToLower() == music.ToLower()).First();

                player.Open(new Uri(@fullPath.FullName, UriKind.Relative));
                player.MediaEnded += MediaPlayer_Loop;
                player.Play();
            }
            else if (player.Source.ToString() != (AppGlobals.soundDir + "/" + music.Trim() + ".mp3"))
            {
                var fullPath = AppGlobals.soundDir + "/" + music.Trim();

                player.Open(new Uri(@fullPath, UriKind.Relative));
                player.MediaEnded += MediaPlayer_Loop;
                player.Play();
            }
        }
开发者ID:Dascarecrow72,项目名称:AdventureVerse,代码行数:32,代码来源:MusicPlayer.cs

示例8: FileManager

        public ActionResult FileManager(string path = @"E:\Rooms\u334041")
        {
            DirectoryInfo fdir = new DirectoryInfo(path);

            List<string> dataDir = new List<string>();
            string[] dataFile = new string[fdir.GetFiles().Count()];
            Double[] sizeFile = new Double[fdir.GetFiles().Count()];
            string[] fullNameFile = new string[fdir.GetFiles().Count()];

            string[] Drives = Environment.GetLogicalDrives();
            
            foreach (var dir in fdir.GetDirectories())
            {
                dataDir.Add(dir.Name);
            }
            int i = 0;
            foreach (var file in fdir.GetFiles())
            {
                dataFile[i] = file.Name;
                sizeFile[i] = Math.Round(((Double)file.Length / 1024.0), 2);
                fullNameFile[i] = file.FullName;
                i++;
            }
            ViewBag.file = dataFile;
            ViewBag.dir = dataDir;
            ViewBag.sizeFile = sizeFile;
            ViewBag.fullNameFile = fullNameFile;
            ViewBag.path = path;
            ViewBag.nameThisDir = fdir.Name;
            ViewBag.drive = Drives;
            return View();
        }
开发者ID:ilnur-slv,项目名称:ilnur-slv.ru,代码行数:32,代码来源:HomeController.cs

示例9: GetFilesInDirSortedByDate

        public static FileInfo[] GetFilesInDirSortedByDate(string directory, string FilePattern, bool bAscOrder)
        {
            FileInfo[] fiArr;
            try
            {
                // make a reference to our directory
                DirectoryInfo di = new DirectoryInfo(directory);
                // get a reference to each file (matching our pattern if necessary)
                if ((FilePattern != null) & (FilePattern.Length != 0) & (FilePattern
                != "*.*"))
                    fiArr = di.GetFiles(FilePattern);
                else
                    fiArr = di.GetFiles();

                // sort it as needed
                if (bAscOrder)
                    Array.Sort(fiArr, new SortFileInfoByDateAsc());
                else
                    Array.Sort(fiArr, new SortFileInfoByDateDesc());

                return fiArr;
            }
            catch (Exception ex)
            {
                throw new Exception("An error occurred while retrieving FileInfo for the following values:" + Environment.NewLine +
                    "Directory: " + directory + ", File Pattern: " + FilePattern + ", Asending Order?" + bAscOrder + Environment.NewLine +
                     "Error CNF-335 in " + PROJ_FILE_NAME + ".GetFilesInDirSortedByDate()" + ex.Message);
            }
        }
开发者ID:Amphora2015,项目名称:DemoTest,代码行数:29,代码来源:SempraFileUtils.cs

示例10: LoadReportTransforms

        public void LoadReportTransforms()
        {
            reportTransforms["Summary"] = new ReportData("Summary", false, false);
            DirectoryInfo di= new DirectoryInfo("Xsl");
            FileInfo[] reportFiles = di.GetFiles("*RPT.xslt");
            FileInfo[] csvFiles = di.GetFiles("*CSV.xslt");
            FileInfo[] csvHeaderFiles = di.GetFiles("*CSV_Header.xslt");

            foreach (FileInfo fi in reportFiles)
            {
                String baseName = fi.Name.Replace("RPT.xslt", "");
                String csvName = baseName + "CSV.xslt";
                String csvHeaderName = baseName + "CSV_Header.xslt";
                Boolean hasCSV = false;
                Boolean hasCSVHeader = false;
                foreach (FileInfo fi2 in csvFiles)
                {
                    if (fi2.Name == csvName)
                    {
                        hasCSV = true;
                    }
                }
                foreach (FileInfo fi2 in csvHeaderFiles)
                {
                    if (fi2.Name == csvHeaderName)
                    {
                        hasCSVHeader = true;
                    }
                }
                reportTransforms[baseName] = new ReportData(baseName, hasCSV, hasCSVHeader);
            }
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:32,代码来源:ViewController.cs

示例11: GetAllData

        public IEnumerable<SimpleDataSet> GetAllData(string indexType)
        {
            var config = FileIndexerConfig.Settings;
            var fullPath = HttpContext.Current.Server.MapPath(config.DirectoryToIndex);

            var directory = new DirectoryInfo(fullPath);

            var files = config.Recursive ? directory.GetFiles(config.SupportedFileTypes, SearchOption.AllDirectories) : directory.GetFiles(config.SupportedFileTypes);

            var dataSets = new List<SimpleDataSet>();
            var i = 1; //unique id for each doc

            foreach (var file in files)
            {
                try
                {
                    var simpleDataSet = new SimpleDataSet { NodeDefinition = new IndexedNode(), RowData = new Dictionary<string, string>() };

                    simpleDataSet = ExamineHelper.MapFileToSimpleDataIndexItem(file, simpleDataSet, i, indexType);

                    dataSets.Add(simpleDataSet);
                }
                catch (Exception ex)
                {
                    Log.Add(LogTypes.Error, i, "error processing file  " + file.FullName + " " + ex);
                }

                i++;
            }

            return dataSets;
        }
开发者ID:eitherxor,项目名称:OurUmbraco,代码行数:32,代码来源:FileIndexDataService.cs

示例12: GetAllZarcFiles

 static string[] GetAllZarcFiles(DirectoryInfo directory)
 {
     List<string> allFiles = new List<string>();
     DirectoryInfo[] allDirectory = directory.GetDirectories();
     if (allDirectory.Length > 0)
     {
         foreach (DirectoryInfo single in allDirectory)
         {
             string[] files = GetAllZarcFiles(single);
             allFiles.AddRange(files);
         }
         FileInfo[] fileInfos = directory.GetFiles();
         foreach (FileInfo file in fileInfos)
         {
             if (file.Extension.ToLower().Equals(".zarc"))
             {
                 allFiles.Add(file.FullName);
             }
         }
         return allFiles.ToArray();
     }
     else
     {
         FileInfo[] files = directory.GetFiles();
         foreach (FileInfo file in files)
         {
             if (file.Extension.ToLower().Equals(".zarc"))
             {
                 allFiles.Add(file.FullName);
             }
         }
         return allFiles.ToArray();
     }
 }
开发者ID:romhackingvn,项目名称:Alpha-Translation,代码行数:34,代码来源:Program.cs

示例13: IAChoice

 public IAChoice(AccountUC account)
 {
     InitializeComponent();
     Account = account;
     switch (MainForm.ActualMainForm.Lang)
     {
         case "EN":
             this.Text = "AI Manager";
             DelBt.Text = "Delete";
             LoadBt.Text = "Load";
             AddBt.Text = "Add";
             FilesList.Columns[0].Text = "Name";
             FilesList.Columns[1].Text = "Author";
             FilesList.Columns[2].Text = "Breed";
             break;
     }
     System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\BlueSheep\IAs");
     if (di.GetFiles().Count() == 0)
     {
         System.Windows.Forms.MessageBox.Show("Aucune IA, veuillez en télécharger sur le forum ou créer la vôtre :) ");
     }
     else
     {
         foreach (System.IO.FileInfo file in di.GetFiles())
         {
             if (file.Extension == ".bs")
                 LoadIA(file);
         }
     }
 }
开发者ID:DjTrilogic,项目名称:BlueSheep,代码行数:30,代码来源:IAChoice.cs

示例14: addRepeatableContainers

        private static void addRepeatableContainers(String[] args)
        {
            if (args.Length == 0)
            {
                throw new ArgumentException("Please pass the datadef directory as an argument.");

            }

            DirectoryInfo dir = new DirectoryInfo(args[0]);
            XmlDocument commonDoc = null;
            foreach (FileInfo file in dir.GetFiles("*.xml"))
            {
                if (file.Name == "common.xml")
                {
                    commonDoc = new XmlDocument();
                    commonDoc.Load(file.FullName);
                    break;
                }
            }

            foreach (FileInfo file in dir.GetFiles("*.xml"))
            {
                if (file.Name != "common.xml")
                {
                    UpdateLegacyMetadata(file, commonDoc["adk"]);
                }
            }

            File.Delete(dir.FullName + "\\common.xml");

            commonDoc.Save(dir.FullName + "\\common.xml");
        }
开发者ID:rafidzal,项目名称:OpenADK-csharp,代码行数:32,代码来源:Program.cs

示例15: Run

		public static void Run()
		{
			Logger.WriteLine("Running BackupManager", "BackupManager");
			if(!Directory.Exists(Config.Instance.BackupDir))
				Directory.CreateDirectory(Config.Instance.BackupDir);
			var dirInfo = new DirectoryInfo(Config.Instance.BackupDir);
			var backupFileName = $"Backup_{DateTime.Today.ToString("ddMMyyyy")}.zip";

			if (dirInfo.GetFiles().Any(x => x.Name == backupFileName))
			{
				Logger.WriteLine("Backup for today already exists", "BackupManager");
				return;
			}

			try
			{
				var backups = dirInfo.GetFiles("Backup_*");
				while(backups.Count() > MaxBackups)
				{
					var oldest = backups.OrderBy(x => x.CreationTime).First();
					Logger.WriteLine("Deleting old backup: " + oldest.Name, "BackupManager");
					oldest.Delete();
					backups = dirInfo.GetFiles("Backup_*");
				}
			}
			catch(Exception ex)
			{
				Logger.WriteLine("Error deleting old backup: " + ex, "BackupManager");
			}

			Logger.WriteLine("Creating backup for today", "BackupManager");

			CreateBackup(backupFileName);
		}
开发者ID:nakaneku,项目名称:Hearthstone-Deck-Tracker,代码行数:34,代码来源:BackupManager.cs


注:本文中的System.IO.DirectoryInfo.GetFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。