本文整理汇总了C#中FileSystem.DirectoryExists方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystem.DirectoryExists方法的具体用法?C# FileSystem.DirectoryExists怎么用?C# FileSystem.DirectoryExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem.DirectoryExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshAssemblies
private static void RefreshAssemblies(ILog log)
{
var fileSystem = new FileSystem();
var packagesFolder = Path.Combine(fileSystem.CurrentDirectory, "packages");
if(fileSystem.DirectoryExists(packagesFolder))
{
// Delete any blacklisted packages to avoid various issues with PackageAssemblyResolver
// https://github.com/scriptcs/scriptcs/issues/511
foreach (var packagePath in
_blacklistedPackages.SelectMany(packageName => Directory.GetDirectories(packagesFolder)
.Where(d => new DirectoryInfo(d).Name.StartsWith(packageName, StringComparison.InvariantCultureIgnoreCase)),
(packageName, packagePath) => new {packageName, packagePath})
.Where(t => fileSystem.DirectoryExists(t.packagePath))
.Select(t => @t.packagePath))
{
fileSystem.DeleteDirectory(packagePath);
}
}
var par = new PackageAssemblyResolver(fileSystem, new PackageContainer(fileSystem, log), log);
_assemblies = par.GetAssemblyNames(fileSystem.CurrentDirectory).ToList();
// Add the assemblies in the current directory
_assemblies.AddRange(Directory.GetFiles(fileSystem.CurrentDirectory, "*.dll")
.Where(a => new AssemblyUtility().IsManagedAssembly(a)));
}
示例2: DirectoryExists
public void DirectoryExists()
{
var curDirectory = Directory.GetCurrentDirectory();
var existingFile = Path.Combine(curDirectory, "../../");
var fileSystem = new FileSystem();
Assert.IsTrue(fileSystem.DirectoryExists(existingFile));
var notExistingFile = Path.Combine(curDirectory, "../../" + notExisting + "/");
Assert.IsFalse(fileSystem.DirectoryExists(notExistingFile));
}
示例3: Main
public static int Main(string[] args)
{
var fileSystem = new FileSystem();
string srcDirectory = AppDomain.CurrentDomain.BaseDirectory.ParentDirectory().ParentDirectory().ParentDirectory().ParentDirectory();
string buildDirectory = args.Any()
? args.Single()
: srcDirectory.ParentDirectory().ParentDirectory().AppendPath("buildsupport");
Console.WriteLine("Trying to copy to " + buildDirectory);
if (!fileSystem.DirectoryExists(buildDirectory))
{
throw new ApplicationException("Could not find the buildsupport directory");
}
var targetDirectory = buildDirectory.AppendPath("FubuDocs");
fileSystem.CreateDirectory(targetDirectory);
fileSystem.CleanDirectory(targetDirectory);
var fromDirectory = srcDirectory.AppendPath("FubuDocsRunner").AppendPath("bin").AppendPath("debug");
var files = FileSet.Deep("*.dll;*.pdb;*.exe");
fileSystem.FindFiles(fromDirectory, files).Each(file => {
Console.WriteLine("Copying {0} to {1}", file, targetDirectory);
fileSystem.Copy(file, targetDirectory, CopyBehavior.overwrite);
});
return 0;
}
示例4: BatchTest
public async Task BatchTest()
{
FileSystem fs = new FileSystem();
string path = @"C:\PathToSpecs"; //path to specs
Assert.True(fs.DirectoryExists(path), $"{path} does not exist");
// get all of the json and yaml files from filesystem
string[] files = fs.GetFilesByExtension(path, SearchOption.AllDirectories, "json", "yaml");
Assert.True(files.Count() > 0, $"{path} does not contain any json or yaml files");
foreach (string file in files)
{
// Comment this block out if not needed
if (!fs.ReadFileAsText(file).Contains(@"""swagger"": ""2.0"""))
{
//skip files that are not swagger files.
continue;
}
using (var memoryFileSystem = GenerateCodeForTestFromSpec(file))
{
// Expected Files
Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);
Assert.True(memoryFileSystem.GetFiles(@"GeneratedCode\Models\", "*.cs", SearchOption.TopDirectoryOnly).GetUpperBound(0) > 0);
var result = await Compile(memoryFileSystem);
// filter the warnings
var warnings = result.Messages.Where(
each => each.Severity == DiagnosticSeverity.Warning
&& !SuppressWarnings.Contains(each.Id)).ToArray();
// use this to dump the files to disk for examination
// memoryFileSystem.SaveFilesToTemp(file.Name);
// filter the errors
var errors = result.Messages.Where(each => each.Severity == DiagnosticSeverity.Error).ToArray();
Write(warnings, memoryFileSystem);
Write(errors, memoryFileSystem);
// use this to write out all the messages, even hidden ones.
// Write(result.Messages, memoryFileSystem);
// Don't proceed unless we have zero Warnings.
Assert.Empty(warnings);
// Don't proceed unless we have zero Errors.
Assert.Empty(errors);
// Should also succeed.
Assert.True(result.Succeeded);
}
}
}
示例5: FindSettings
public ApplicationSettings FindSettings()
{
if (Location.IsEmpty())
{
return new ApplicationSettings{
PhysicalPath = ".".ToFullPath(),
ParentFolder = ".".ToFullPath()
};
}
var system = new FileSystem();
if (system.FileExists(Location) && system.IsFile(Location))
{
Console.WriteLine("Reading application settings from " + Location);
return ApplicationSettings.Read(Location);
}
if (system.DirectoryExists(Location))
{
return findFromDirectory(system);
}
return findByName(system);
}