本文整理汇总了C#中System.IO.DirectoryInfo.GetDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetDirectories方法的具体用法?C# DirectoryInfo.GetDirectories怎么用?C# DirectoryInfo.GetDirectories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.GetDirectories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WalkTreeDirectory
public static void WalkTreeDirectory(DirectoryInfo d, int depth)
{
try {
FileInfo[] files = d.GetFiles();
foreach (FileInfo file in files)
{
for (int i = 0; i < depth; i++)
Console.Write(" ");
Console.WriteLine("File name: {0}, Size: {1}", file.Name, file.Length);
}
DirectoryInfo[] directories = d.GetDirectories();
foreach (DirectoryInfo di in directories)
{
for (int i = 0; i < depth; i++)
Console.Write(" ");
Console.WriteLine("Directory name:" + di.Name);
WalkTreeDirectory(di, depth + 1);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
示例2: LoadPlugins
public void LoadPlugins(string pluginPath, bool checkSubDirs)
{
if(!Directory.Exists(pluginPath))
return;
if(Plugins.Any())
UnloadPlugins();
var dirInfo = new DirectoryInfo(pluginPath);
var files = dirInfo.GetFiles().Select(f => f.FullName).ToList();
if(checkSubDirs)
{
foreach(var dir in dirInfo.GetDirectories())
files.AddRange(dir.GetFiles().Select(f => f.FullName));
}
foreach(var file in files)
{
var fileInfo = new FileInfo(file);
if(fileInfo.Extension.Equals(".dll"))
{
var plugins = GetModule(file, typeof(IPlugin));
foreach(var p in plugins)
Plugins.Add(p);
}
}
Logger.WriteLine("Loading Plugins...", "PluginManager");
LoadPluginSettings();
}
示例3: AddXmlNodes
//Appends the any xml file/folder nodes onto the folder
private void AddXmlNodes(FolderCompareObject folder, int numOfPaths, XmlDocument xmlDoc)
{
List<XMLCompareObject> xmlObjList = new List<XMLCompareObject>();
List<string> xmlFolderList = new List<string>();
for (int i = 0; i < numOfPaths; i++)
{
string path = Path.Combine(folder.GetSmartParentPath(i), folder.Name);
if (Directory.Exists(path))
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] fileList = dirInfo.GetFiles();
DirectoryInfo[] dirInfoList = dirInfo.GetDirectories();
string xmlPath = Path.Combine(path, CommonXMLConstants.MetadataPath);
if (!File.Exists(xmlPath))
continue;
CommonMethods.LoadXML(ref xmlDoc, xmlPath);
xmlObjList = GetAllFilesInXML(xmlDoc);
xmlFolderList = GetAllFoldersInXML(xmlDoc);
RemoveSimilarFiles(xmlObjList, fileList);
RemoveSimilarFolders(xmlFolderList, dirInfoList);
}
AddFileToChild(xmlObjList, folder, i, numOfPaths);
AddFolderToChild(xmlFolderList, folder, i, numOfPaths);
xmlObjList.Clear();
xmlFolderList.Clear();
}
}
示例4: GetBabylonScenes
public string GetBabylonScenes(string rootPath)
{
try
{
var dir = new DirectoryInfo(rootPath);
var subDirs = dir.GetDirectories();
var files = new List<JObject>();
foreach (var directory in subDirs)
{
var babylonFiles = directory.GetFiles("*.babylon");
if (babylonFiles.Length == 0)
continue;
foreach (var file in babylonFiles)
{
var linkName = directory.Name + "/" + Path.GetFileNameWithoutExtension(file.Name);
files.Add(new JObject(
new JProperty("url", Url.Action("Index", "BabylonJSDemo", new { demoFolderName = directory.Name, demoFile = file.Name })),
new JProperty("linkName", linkName)
));
}
}
var json = new JObject(new JProperty("files", files));
return json.ToString(Newtonsoft.Json.Formatting.None);
}
catch
{
var json = new JObject(new JProperty("files", ""));
return json.ToString(Newtonsoft.Json.Formatting.None);
}
}
示例5: MountAlbumList
public List<Album> MountAlbumList(DirectoryInfo pFolderArtist)
{
Album album;
List<Album> albumList = new List<Album>();
/*
* Verificando se dentro da pasta do artista tem alguma subpasta;
* Se não tiver, significa que será criado um Album caracterizado como desconhecido
* Se tiver subpasta, então montará a lista de albuns.
*
*/
if (pFolderArtist.GetDirectories().Length > 0)
{
DirectoryInfo[] foldersAlbum = pFolderArtist.GetDirectories();
foreach (DirectoryInfo folderAlbum in foldersAlbum)
{
_name = String.Empty;
_oldname = String.Empty;
MountAlbum(albumList, folderAlbum);
}
}
else
{
/*
* Entrará aqui somente se não existir nenhum subpasta referente ao album
*/
album = new Album();
album.name = pFolderArtist.Name;
album.path = pFolderArtist.Parent.Name;
album.musicList=MountListMusic(pFolderArtist);
albumList.Add(album);
}
return albumList;
}
示例6: MountArtistList
public List<Artist> MountArtistList(DirectoryInfo pFolderMedia)
{
List<Artist> artistList = new List<Artist>();
Artist artist;
/*
* Verificando se a pasta da Media tem subpastas
* Se não tiver subpasta(s) significa que não existem artistas.
* Se tiver subpasta(s) então entrará na condição para criar um objeto para cada artista;
*
*/
if (pFolderMedia.GetDirectories().Length > 0)
{
DirectoryInfo[] foldersArtist = pFolderMedia.GetDirectories();
foreach (DirectoryInfo folderArtist in foldersArtist)
{
artist = new Artist();
artist.name = folderArtist.Name;
artist.path = folderArtist.Parent.Name;
artist.albumList = MountAlbumList(folderArtist);
artistList.Add(artist);
}
}
else
{
artist = new Artist();
artist.name = "Artista desconhecido";
artist.path = pFolderMedia.Name;
artist.albumList = MountAlbumList(pFolderMedia);
artistList.Add(artist);
}
return artistList;
}
示例7: XmlGeneratedTraversedTreeRecursivly
public static void XmlGeneratedTraversedTreeRecursivly(XmlTextWriter writer, DirectoryInfo rootDirectory)
{
if (!rootDirectory.GetDirectories().Any() && !rootDirectory.GetFiles().Any())
{
return;
}
writer.WriteStartElement("dir");
writer.WriteAttributeString("name", rootDirectory.Name);
foreach (var file in rootDirectory.GetFiles())
{
writer.WriteStartElement("file");
writer.WriteAttributeString("name", Path.GetFileNameWithoutExtension(file.ToString()));
writer.WriteAttributeString("type", Path.GetExtension(file.ToString()).Substring(1));
writer.WriteEndElement();
}
foreach (var dir in rootDirectory.GetDirectories())
{
XmlGeneratedTraversedTreeRecursivly(writer, dir);
}
writer.WriteEndElement();
}
示例8: RecurseDirectory
private void RecurseDirectory(LinkedList<PlsqlObject> plsqlObjects, string directoryPath)
{
ArrayList objectsFromOneFile;
DirectoryInfo di = new DirectoryInfo(directoryPath);
if (di.GetDirectories().Length > 0)
{
foreach (DirectoryInfo dir in di.GetDirectories())
{
RecurseDirectory(plsqlObjects, dir.FullName);
}
}
//lets go through all files first
foreach (FileInfo file in di.GetFiles())
{
List<string> list = new List<string>(PlsqlConstants.plsqlAnalyzedEtensions);
//we looka only at regular PlSql extensions
if (!list.Contains(file.Extension))
continue;
if ((objectsFromOneFile = ParseFile(file.FullName)).Count > 0)
{
foreach (PlsqlObject o in objectsFromOneFile)
{
plsqlObjects.AddLast(o);
}
}
}
}
示例9: GetBundleReferences
private static string[] GetBundleReferences(string path)
{
var paths = new List<string>();
if (path.StartsWith("~/"))
{
path = path.Substring(2);
}
path = Path.Combine(appPath, path);
var folder = new DirectoryInfo(path);
if (folder.Exists)
{
if (folder.GetFiles().Any())
{
string[] exclusions = extExclusions;
if (customExclusions != null)
{
exclusions = extExclusions.Concat(customExclusions).ToArray();
}
var files = folder.GetFiles().Where(f => !exclusions.Contains(f.Extension.ToLower()));
paths.AddRange(files.Select(file => GetVirtualPath(file.FullName)));
}
if (folder.GetDirectories().Any())
{
paths.AddRange(folder.GetDirectories().SelectMany(d => GetBundleReferences(d.FullName)));
}
}
return paths.ToArray();
}
示例10: WebCompilationContext
public WebCompilationContext(DirectoryInfo siteRoot, DirectoryInfo temporarySourceFilesDirectory) : base(
siteRoot.GetDirectories("bin")[0],
siteRoot,
siteRoot.GetDirectories("views")[0],
temporarySourceFilesDirectory)
{
}
示例11: CreateDirectory
/// <summary>
/// Creates the directory for writing test files. We use the %TEMP% directory here.
/// </summary>
/// <param name="folder">The folder.</param>
/// <returns></returns>
public static DirectoryInfo CreateDirectory(string folder)
{
var path = //Environment.CurrentDirectory;
Path.Combine(Path.GetTempPath(), "DatabaseSchemaReader");
var directory = new DirectoryInfo(path);
if (!directory.Exists)
{
directory.Create();
}
if (directory.GetDirectories(folder).Any())
{
//if it's already there, clear it out
var sub = directory.GetDirectories(folder).First();
try
{
sub.Delete(true);
}
catch (UnauthorizedAccessException)
{
//can't access it, carry on
}
}
var subdirectory = directory.CreateSubdirectory(folder);
//because it may not actually have been created...
if (!subdirectory.Exists)
subdirectory.Create();
return subdirectory;
}
示例12: RunDiagnostics
public static List<string> RunDiagnostics()
{
List<string> ret = new List<string>();
if (Settings.Current[Constants.BASE_PATH_NAME] == null)
Settings.Current[Constants.BASE_PATH_NAME] = Constants.DEFAULT_BASE_BATH;
DirectoryInfo di = new DirectoryInfo((string)Settings.Current[Constants.BASE_PATH_NAME]);
if (!di.Exists)
ret.Add("Unable to locate base freeswitch operating path at " + di.FullName + ". Please corrected the system setting " + Constants.BASE_PATH_NAME);
else
{
ret.Add("Located the base freeswitch operating path at " + di.FullName);
if (di.GetDirectories(AUDIO_PATH).Length == 0)
ret.Add("Unable to locate the freeswitch audio files path at " + di.FullName + Path.DirectorySeparatorChar + AUDIO_PATH);
else
ret.Add("Locate the freeswitch audio files path at " + di.FullName + Path.DirectorySeparatorChar + AUDIO_PATH);
if (di.GetDirectories(SCRIPT_PATH).Length == 0)
ret.Add("Unable to locate the freeswitch script files path at " + di.FullName + Path.DirectorySeparatorChar + SCRIPT_PATH);
else
ret.Add("Locate the freeswitch script files path at " + di.FullName + Path.DirectorySeparatorChar + SCRIPT_PATH);
if (di.GetDirectories(VOICEMAIL_PATH).Length == 0)
ret.Add("Unable to locate the freeswitch voicemail files path at " + di.FullName + Path.DirectorySeparatorChar + VOICEMAIL_PATH);
else
ret.Add("Locate the freeswitch voicemail files path at " + di.FullName + Path.DirectorySeparatorChar + VOICEMAIL_PATH);
}
return ret;
}
示例13: Start
protected Process Start(DirectoryInfo dir)
{
if (dir.GetFiles().Length == 0 && dir.GetDirectories().Length == 1) {
return Start(dir.GetDirectories()[0]);
}
bool inifound = false;
bool fexefound = false;
RenameFiles(dir, ref inifound, ref fexefound);
foreach(DirectoryInfo nextdir in dir.GetDirectories()) {
if (nextdir.Name.ToLower() == "lvl") {
CreateDirRenamer(nextdir.FullName, "Lvl");
if (File.Exists(nextdir.FullName + "\\Level.ini")) inifound = true;
}
else if (nextdir.Name.ToLower() == "gfx") {
CreateDirRenamer(nextdir.FullName, "GFX");
if (Directory.Exists(nextdir.FullName + "\\Wasser"))
CreateDirRenamer(nextdir.FullName + "\\Wasser", "GFX\\Wasser");
}
else if (nextdir.Name.ToLower() == "sfx") CreateDirRenamer(nextdir.FullName, "SFX");
else if (nextdir.Name.ToLower() == "video") CreateDirRenamer(nextdir.FullName, "Video");
else RenameFiles(nextdir, ref inifound, ref fexefound);
}
if (!inifound) {
if (Directory.Exists(dir.FullName + "\\Lvl"))
new Task.IniCreator(new DirectoryInfo(dir.FullName + "\\Lvl").GetFiles("*.lv6"));
else new Task.IniCreator(dir.GetFiles("*.lv6"));
CreateRenamer(@"Bonus\temp\Level.ini", @"Lvl\", "Level.ini");
}
else {
new Task.IniFixer();
}
Task.TaskManager.DoAll();
return Process.Start("T2002.exe");
}
示例14: EmptyDirectory
static int EmptyDirectory(DirectoryInfo Directory)
{
int removedDirectories = 0;
try
{
foreach (DirectoryInfo NestedDirectory in Directory.GetDirectories())
{
removedDirectories += EmptyDirectory(NestedDirectory);
}
if (Directory.GetFiles().Length == 0 && Directory.GetDirectories().Length == 0)
{
Console.Write("Removing " + Directory.Name + "...");
try
{
Directory.Delete();
removedDirectories++;
Console.WriteLine(" Success");
}
catch
{
Console.WriteLine(" Failed");
}
}
}
catch
{
Console.WriteLine(Directory.Name + " is Restricted");
}
return removedDirectories;
}
示例15: Handle
/// <summary>
/// Handles the specified request.
/// </summary>
/// <param name="request">The request.</param>
public void Handle(DeployRequestDto request)
{
DirectoryInfo directory = new DirectoryInfo(request.IntermediateDirectory);
var signalrHub = new SignalrHub();
//for deleting all the files
try
{
foreach (FileInfo file in directory.GetFiles())
{
file.Delete();
}
//for deleting all the directories
foreach (var dir in directory.GetDirectories())
{
dir.Delete(true);
}
}
catch (AggregateException ex)
{
throw ex;
}
//Copy only if the direcory is empty
if (!directory.GetDirectories().Any() && !directory.GetFiles().Any())
{
//unzipping and extracting data to the deploy path
ZipFile.ExtractToDirectory(request.SourcePath, request.IntermediateDirectory);
}
signalrHub.Publish("SqlDeployment", "Sql Scripts deployed to intermediate folder successfully.");
}