本文整理汇总了C#中System.IO.DirectoryInfo.EnumerateFiles方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.DirectoryInfo.EnumerateFiles方法的具体用法?C# System.IO.DirectoryInfo.EnumerateFiles怎么用?C# System.IO.DirectoryInfo.EnumerateFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了System.IO.DirectoryInfo.EnumerateFiles方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasTestData
public void HasTestData()
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(TestFolder);
var files = dir.EnumerateFiles();
Assert.NotEmpty(files);
}
示例2: ApiWrapperWithLogger
static ApiWrapperWithLogger()
{
exeDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
logDir = new System.IO.DirectoryInfo(exeDir + "\\NetworkLogs");
if (logDir.Exists == false)
logDir.Create();
else
foreach (var item in logDir.EnumerateFiles())
item.Delete();
}
示例3: Main
static void Main(string[] args)
{
//Works fine
System.IO.DirectoryInfo sysDirectory = new System.IO.DirectoryInfo("C:\\TEST");
sysDirectory.EnumerateFiles();
//Does not compile:
//'Pri.LongPath.DirectoryInfo' does not contain a definition for 'EnumerateFiles'
//and no extension method 'EnumerateFiles' accepting a first argument of type
//'Pri.LongPath.DirectoryInfo' could be found (are you missing a using directive or an assembly reference?)
Pri.LongPath.DirectoryInfo longDirectory = new Pri.LongPath.DirectoryInfo("C:\\TEST");
longDirectory.EnumerateFiles();
}
示例4: AddFolder
private PackageFileSourceInfo AddFolder(PackageHeirarchyItem parent, string filePath)
{
PackageHeirarchyItem newItem = null;
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(filePath);
if (parent != null && !Contains(parent, dir.Name))
{
newItem = new PackageHeirarchyItem(filePath);
newItem.Name = dir.Name;
newItem.Parent = parent;
parent.Children.Add(newItem);
// EnumerateFiles is not working on mono for some reason, therefore use GetFiles instead,
IEnumerable<System.IO.FileInfo> files;
if(TraceLabSDK.RuntimeInfo.IsRunInMono)
{
files = dir.GetFiles();
}
else
{
files = dir.EnumerateFiles();
}
foreach (System.IO.FileInfo file in files)
{
AddFile(newItem, file.FullName);
}
foreach (System.IO.DirectoryInfo subDir in dir.EnumerateDirectories())
{
AddFolder(newItem, subDir.FullName);
}
}
return newItem;
}
示例5: loadImages
private void loadImages()
{
FolderBrowserDialog browser = new FolderBrowserDialog();
DialogResult result;
do{
result = browser.ShowDialog();
}while(result != DialogResult.OK);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(browser.SelectedPath);
IEnumerable<System.IO.FileInfo> files = dir.EnumerateFiles();
IEnumerator<System.IO.FileInfo> fileEnumer = files.GetEnumerator();
while (fileEnumer.MoveNext())
{
System.IO.FileInfo file = fileEnumer.Current;
if (file.Extension == ".gif")
{
Image img = Image.FromFile(file.FullName);
int capacity = images.Capacity;
images.Add(img);
}
}
loaded = true;
iterator = images.GetEnumerator();
}
示例6: CreateSeedPageTemplates
/// <summary>
/// Dupe-safe uses PageTemplate.ViewName to prevent dupes
/// </summary>
private static List<PageTemplate> CreateSeedPageTemplates(this IGstoreDb storeDb, string virtualPath, Client client)
{
if (storeDb == null)
{
throw new ArgumentNullException("db");
}
if (string.IsNullOrEmpty(virtualPath))
{
throw new ArgumentNullException("virtualPath");
}
if (client == null)
{
throw new ArgumentNullException("client");
}
string path = string.Empty;
if (HttpContext.Current == null)
{
string assemblyPath = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
string directoryName = System.IO.Path.GetDirectoryName(assemblyPath).Replace("GStore\\GStoreData\\", "GStore\\GStoreWeb\\");
path = System.IO.Path.Combine(directoryName, "..\\.." + virtualPath.TrimStart('~').Replace('/', '\\')).Replace("%20", " ");
if (!System.IO.Directory.Exists(path))
{
throw new ApplicationException("Page Templates folder could not be found in file system at path: " + path + ". Please run the web site first to populate the database.");
}
}
else
{
path = HttpContext.Current.Server.MapPath(virtualPath);
}
if (!System.IO.Directory.Exists(path))
{
throw new ApplicationException("Page Templates folder could not be found in file system web server at path: " + path + ".");
}
System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(path);
IEnumerable<System.IO.FileInfo> files = folder.EnumerateFiles("Page *.cshtml");
int counter = 0;
List<PageTemplate> newTemplates = new List<PageTemplate>();
foreach (System.IO.FileInfo file in files)
{
string name = file.Name.Substring(5, ((file.Name.Length - 5) - 7)) + " Template";
if (!client.PageTemplates.Any(pt => pt.Name.ToLower() == name.ToLower()))
{
string viewName = file.Name.Replace(".cshtml", "");
if (!client.PageTemplates.Any(pt => pt.ViewName.ToLower() == viewName.ToLower()))
{
counter++;
PageTemplate pageTemplate = storeDb.PageTemplates.Create();
pageTemplate.Name = name;
pageTemplate.ViewName = viewName;
pageTemplate.Order = 2000 + counter;
if (name.ToLower() == "custom html page template")
{
pageTemplate.Order = 9000 + counter;
}
pageTemplate.Description = pageTemplate.Name;
pageTemplate.IsPending = false;
pageTemplate.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
pageTemplate.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
pageTemplate.Client = client;
pageTemplate.ClientId = client.ClientId;
storeDb.PageTemplates.Add(pageTemplate);
newTemplates.Add(pageTemplate);
}
}
}
storeDb.SaveChangesEx(true, false, false, false);
return newTemplates;
}
示例7: Load
public static FilmBox Load(FilmSession filmSession, string filmBoxFolder)
{
var filmBoxFile = string.Format(@"{0}\FilmBox.dcm", filmBoxFolder);
var file = DicomFile.Open(filmBoxFile);
var filmBox = new FilmBox(filmSession, file.FileMetaInfo.MediaStorageSOPInstanceUID, file.Dataset);
var imagesFolder = new System.IO.DirectoryInfo(string.Format(@"{0}\Images", filmBoxFolder));
foreach (var image in imagesFolder.EnumerateFiles("*.dcm"))
{
var imageBox = ImageBox.Load(filmBox, image.FullName);
filmBox.BasicImageBoxes.Add(imageBox);
}
return filmBox;
}
示例8: GetInputVectors
private void GetInputVectors()
{
if (_appSettings.imageDirectory == "")
{
return;
}
_appSettings.images.Clear();
// Get image files by filtering by extensions
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(_appSettings.imageDirectory);
string[] extensions = new string[] { ".bmp", ".jpg", ".png", ".gif" };
var allowedExtensions = new HashSet<string>(extensions, StringComparer.OrdinalIgnoreCase);
System.IO.FileInfo[] fileInfos = directoryInfo
.EnumerateFiles("*", System.IO.SearchOption.AllDirectories)
.Where(f => allowedExtensions.Contains(f.Extension)).ToArray();
foreach (System.IO.FileInfo f in fileInfos)
{
using (Bitmap img = new Bitmap(f.FullName))
{
try
{
// Feature Extraction
ImageData imgData = PictureSOM.SOMHelper.GetImageData(img);
imgData.m_fileName = f.Name;
imgData.m_directoryName = f.DirectoryName;
Console.WriteLine(imgData.m_fullName);
// Test experimental features here
//float[] testFeature = Features.calculateCEDD_Compact(img);
_appSettings.images.Add(imgData);
}
catch(Exception)
{
Console.WriteLine("Could not add " + f.FullName);
}
}
}
}