本文整理汇总了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);
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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;
}
示例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");
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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");
}
示例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);
}