本文整理汇总了C#中System.IO.DirectoryInfo.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Contains方法的具体用法?C# DirectoryInfo.Contains怎么用?C# DirectoryInfo.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncDirs
static int SyncDirs(string sourceDir, string destDir, bool onlyLog = true)
{
int totalDirs = 0;
if (!Directory.Exists(sourceDir))
{
Console.WriteLine("Dir not exist: " + sourceDir);
return totalDirs;
}
if (!Directory.Exists(destDir))
{
Console.WriteLine("Dir not exist: " + destDir);
return totalDirs;
}
var destDirs = new DirectoryInfo(destDir).GetDirectories().Select(d => d.Name).ToList();
foreach(var sourceDirName in (new DirectoryInfo(sourceDir).GetDirectories()))
{
if (!destDirs.Contains(sourceDirName.Name))
{
totalDirs++;
string newDir = Path.Combine(destDir, sourceDirName.Name);
if (onlyLog)
{
Console.WriteLine("Create dir {0}?", newDir);
}else
{
Console.WriteLine("Create dir {0}", newDir);
Directory.CreateDirectory(newDir);
}
}
}
return totalDirs;
}
示例2: CopyDllsForDomainLoadingDebug
/// <summary>
/// This is required for debugging as NHibernate needs to load the DLLs and seems to only look in the current folder.
/// When run live it will be run via powershell which will put the EXE in the destination folder.
/// Debugging will have to be run through here, NHMigrate will not work correctly.
/// </summary>
/// <param name="projectFolder"></param>
private void CopyDllsForDomainLoadingDebug(string projectFolder)
{
var projectDirectory = new DirectoryInfo(projectFolder);
var executingBinFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
var currentFilesInDestination = new DirectoryInfo(executingBinFolder).GetFiles("*.dll").Select(f => f.Name).ToList();
var dlls = projectDirectory.GetFiles("*.dll");
foreach (var fileInfo in dlls)
{
var destFileName = Path.Combine(executingBinFolder, fileInfo.Name);
if (currentFilesInDestination.Contains(fileInfo.Name))
{
try
{
File.Delete(destFileName);
}
catch (Exception)
{
//try and delete the old files, ignore errors
}
};
File.Copy(fileInfo.FullName, destFileName);
}
}
示例3: IsContainedWithin
/// <summary>
/// Determines if the file or directory is contained within the the other directory at any depth.
/// </summary>
public static bool IsContainedWithin(this FileSystemInfo fileOrDirectory, DirectoryInfo otherDir)
{
return otherDir.Contains(fileOrDirectory);
}
示例4: ApplyDeltaPackage
public ReleasePackage ApplyDeltaPackage(ReleasePackage basePackage, ReleasePackage deltaPackage, string outputFile)
{
Contract.Requires(deltaPackage != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
string workingPath;
string deltaPath;
using (Utility.WithTempDirectory(out deltaPath, localAppDirectory))
using (Utility.WithTempDirectory(out workingPath, localAppDirectory)) {
var fz = new FastZip();
fz.ExtractZip(deltaPackage.InputPackageFile, deltaPath, null);
fz.ExtractZip(basePackage.InputPackageFile, workingPath, null);
var pathsVisited = new List<string>();
var deltaPathRelativePaths = new DirectoryInfo(deltaPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(deltaPath + Path.DirectorySeparatorChar, ""))
.ToArray();
// Apply all of the .diff files
deltaPathRelativePaths
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase) ||
!deltaPathRelativePaths.Contains(x.Replace(".diff", ".bsdiff")))
.ForEach(file => {
pathsVisited.Add(Regex.Replace(file, @"\.(bs)?diff$", "").ToLowerInvariant());
applyDiffToFile(deltaPath, file, workingPath);
});
// Delete all of the files that were in the old package but
// not in the new one.
new DirectoryInfo(workingPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(workingPath + Path.DirectorySeparatorChar, "").ToLowerInvariant())
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) && !pathsVisited.Contains(x))
.ForEach(x => {
this.Log().Info("{0} was in old package but not in new one, deleting", x);
File.Delete(Path.Combine(workingPath, x));
});
// Update all the files that aren't in 'lib' with the delta
// package's versions (i.e. the nuspec file, etc etc).
deltaPathRelativePaths
.Where(x => !x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.ForEach(x => {
this.Log().Info("Updating metadata file: {0}", x);
File.Copy(Path.Combine(deltaPath, x), Path.Combine(workingPath, x), true);
});
this.Log().Info("Repacking into full package: {0}", outputFile);
fz.CreateZip(outputFile, workingPath, true, null);
}
return new ReleasePackage(outputFile);
}
示例5: Clean
//.........这里部分代码省略.........
"wp",
"wp7",
"wp75",
"wp8",
"wp81",
"wpa81",
// Universal Windows Platform
"uap",
"uap10",
// .NET Standard
// See here: https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
"netstandard",
"netstandard1.0",
"netstandard1.1",
"netstandard1.2",
"netstandard1.3",
"netstandard1.4",
"netstandard1.5",
"netstandard1.6",
// .NET Core App
"netcoreapp",
"netcoreapp1.0",
"cf", // compact framework
"monoandroid",
"monotouch",
"xamarin.ios10",
"xamarin.mac20"
};
string[] libDirectories = Directory.GetDirectories(packageInstallDirectory + "/lib");
foreach (var directory in libDirectories)
{
string directoryName = new DirectoryInfo(directory).Name.ToLower();
if (directoriesToDelete.Any(directoryName.Contains))
{
LogVerbose("Deleting unused directory: {0}", directory);
DeleteDirectory(directory);
}
else if (directoryName.Contains("net20") && (has30 || has35))
{
// if .NET 2.0 exists, keep it, unless there is also a .NET 3.0 or 3.5 version as well
LogVerbose("Deleting net20: {0}", directory);
DeleteDirectory(directory);
}
else if (directoryName.Contains("net30") && has35)
{
// if .NET 3.0 exists, keep it, unless there is also a .NET 3.5 version as well
LogVerbose("Deleting net30: {0}", directory);
DeleteDirectory(directory);
}
}
}
if (Directory.Exists(packageInstallDirectory + "/tools"))
{
// Delete all JavaScript in the tools directory since Unity will think it's "UnityScript"
DeleteAllFiles(packageInstallDirectory + "/tools", "*.js");
// Delete all DLLs in the tools directory since we can't tell which .NET version they target
DeleteAllFiles(packageInstallDirectory + "/tools", "*.dll");
}
// delete all PDB files since Unity uses Mono and requires MDB files, which causes it to output "missing MDB" errors
DeleteAllFiles(packageInstallDirectory, "*.pdb");
// if there are native DLLs, copy them to the Unity project root (1 up from Assets)