本文整理汇总了C#中System.IO.DirectoryInfo.GetFile方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetFile方法的具体用法?C# DirectoryInfo.GetFile怎么用?C# DirectoryInfo.GetFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.GetFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Package
public Package(DirectoryInfo packageDirectory)
{
_directoryInfo = packageDirectory;
var jsonFile = _directoryInfo.GetFile("metadata.json");
var yamlFile = _directoryInfo.GetFile("metadata.yml");
if (jsonFile.Exists)
{
var se = new Serializer();
Metadata = JsonConvert.DeserializeObject<PackageMetadata>(File.ReadAllText(_directoryInfo.GetFile("metadata.json").FullName));
using (var yamlStream = yamlFile.Open(FileMode.OpenOrCreate))
{
using (var yamlWriter = new StreamWriter(yamlStream, Encoding.UTF8))
{
se.Serialize(yamlWriter, Metadata);
}
}
jsonFile.Delete();
}
var dse = new Deserializer();
//Console.WriteLine("Reading YAML: {0}", yamlFile.FullName);
using (var yamlStream = yamlFile.Open(FileMode.Open))
{
using (var yamlReader = new StreamReader(yamlStream, Encoding.UTF8, true))
{
Metadata = dse.Deserialize<PackageMetadata>(yamlReader);
}
}
}
示例2: CraftitudeProfile
// Constructor
/// <summary>
/// Open a profile (create if not exist) and load it.
/// </summary>
/// <param name="profileDirectory">The root directory of the profile</param>
public CraftitudeProfile(DirectoryInfo profileDirectory)
{
Directory = profileDirectory;
_craftitudeDirectory = Directory.CreateSubdirectory("craftitude");
_craftitudeDirectory.CreateSubdirectory("repositories"); // repository package lists
_craftitudeDirectory.CreateSubdirectory("packages"); // cached package setups
_bsonFile = _craftitudeDirectory.GetFile("profile.bson");
if (!_bsonFile.Exists)
{
ProfileInfo = new ProfileInfo();
}
else
{
using (FileStream bsonStream = _bsonFile.Open(FileMode.OpenOrCreate))
{
using (var bsonReader = new BsonReader(bsonStream))
{
var jsonSerializer = new JsonSerializer();
ProfileInfo = jsonSerializer.Deserialize<ProfileInfo>(bsonReader) ?? new ProfileInfo();
}
}
}
}
示例3: GetFile
private static FileInfo GetFile(DirectoryInfo dirInfo, string relativePath) {
if (!dirInfo.SafeExists()) {
return null;
}
var fileInfo = dirInfo.GetFile(relativePath);
return fileInfo.Exists ? fileInfo : null;
}
示例4: VerifyMeasureAndLocalize
private static void VerifyMeasureAndLocalize(
string testTargetNames, string inDirPath, string expDirPath, DirectoryInfo outDir) {
var ret = Inserter.Run(
new[] {
"-r",
outDir.FullName,
"-t",
outDir.GetDirectory("test").FullName,
});
Assert.That(ret, Is.True);
// jarとdllファイルが存在するか
var jar = outDir.GetFile("CoverageWriter.jar");
Assert.That(jar.Exists, Is.True);
var covInfoFile = outDir.GetFile(OccfNames.CoverageInfo);
var testInfoFile = outDir.GetFile(OccfNames.TestInfo);
var recordFile = outDir.GetFile(OccfNames.Record);
var resultFile = outDir.GetFile("testresult.txt");
var targets = Directory.EnumerateFiles(
expDirPath, "*.java",
SearchOption.AllDirectories)
.Concat(
Directory.EnumerateFiles(
expDirPath, OccfNames.BackupSuffix,
SearchOption.AllDirectories))
.Concat(new[] { covInfoFile.FullName, testInfoFile.FullName });
foreach (var target in targets) {
AssertEqualFiles(target, expDirPath, inDirPath);
}
Compile(outDir.FullName);
RunTest(outDir.FullName, testTargetNames);
var covInfo = CoverageInfo.Read(covInfoFile);
var testInfo = TestInfo.Read(testInfoFile);
testInfo.InitializeForStoringData(true);
BugLocalizer.ReadJUnitResult(resultFile, testInfo);
CoverageDataReader.ReadFile(testInfo, recordFile);
var localizeStatements = BugLocalizer.LocalizeStatements(covInfo, testInfo,
"metrics/BugLocalization.py");
Assert.That(localizeStatements, Is.Not.Null);
}
示例5: MvcDotNetProjectMigrationOptions
public MvcDotNetProjectMigrationOptions(string projectRootPath, string tempWorkingDirectoryPath, IEnumerable<string> extraDirectories, IEnumerable<string> extraFiles)
{
TempWorkingDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), tempWorkingDirectoryPath));
var projectRoot = new DirectoryInfo(projectRootPath);
SourceWebConfig = projectRoot.GetFile("Web.config");
SourceFiles = ListFiles(projectRoot, extraFiles);
SourceDirectories = ListDirectories(projectRoot, extraDirectories);
OverwriteWebConfig = delegate { };
}
示例6: Load
public static CourseSettings Load(DirectoryInfo dir)
{
var file = dir.GetFile("Course.xml");
if (!file.Exists)
return DefaultSettings;
var settings = file.DeserializeXml<CourseSettings>();
if (settings.DefaultLanguageVersions == null)
settings.DefaultLanguageVersions = new Language[0];
if (settings.Preludes == null)
settings.Preludes = new PreludeFile[0];
return settings;
}
示例7: StudentsZipIsBuildingOk
private void StudentsZipIsBuildingOk(Slide slide, ProjectExerciseBlock ex)
{
var tempDir = new DirectoryInfo("./temp");
try
{
Utils.UnpackZip(ex.StudentsZip.Content(), "./temp");
var res = MsBuildRunner.BuildProject(settings.MsBuildSettings, tempDir.GetFile(ex.CsprojFileName).FullName, tempDir);
if (!res.Success)
ReportSlideError(slide, ex.CsprojFileName + " not building! " + res);
}
finally
{
tempDir.Delete(true);
}
}
示例8: CreateLockFile
public void CreateLockFile()
{
var current = new DirectoryInfo(".");
var tempFileName = CreateTempFile();
var lockFileName = current.GetFile("lock-file").FullName;
File.WriteAllText(lockFileName, "test");
try
{
new FileInfo(tempFileName).MoveTo(lockFileName);
throw new AssertionException("MoveTo() should create IOException if destination file already exists");
}
catch (IOException)
{
}
File.ReadAllText(lockFileName).ShouldBeEquivalentTo("test");
}
示例9: Transform
public static void Transform(
this DirectoryInfo dir, string searchPattern, SearchOption searchOption,
DirectoryInfo targetDir,
Action<FileInfo, FileInfo, Dictionary<string, string>> transformer, Dictionary<string, string> args)
{
var files = dir.GetFiles(searchPattern, searchOption);
foreach (var file in files)
{
if (file.FullName.Contains("\\.svn\\"))
continue;
var relFile = dir.CreateRelativePathTo(file);
var finalTargetFile = targetDir.GetFile(relFile);
transformer(file, finalTargetFile, args);
}
}
示例10: InitialCodeIsNotSolutionForProjExercise
private void InitialCodeIsNotSolutionForProjExercise(ExerciseSlide slide)
{
var exercise = (ProjectExerciseBlock)slide.Exercise;
var directoryName = Path.Combine(exercise.SlideFolderPath.FullName, exercise.ExerciseDir);
var excluded = (exercise.PathsToExcludeForChecker ?? new string[0]).Concat(new[] { "bin/*", "obj/*" }).ToList();
var exerciseDir = new DirectoryInfo(directoryName);
var bytes = exerciseDir.ToZip(excluded, new[]
{
new FileContent
{
Path = exercise.CsprojFileName,
Data = ProjModifier.ModifyCsproj(exerciseDir.GetFile(exercise.CsprojFileName),
proj => ProjModifier.PrepareForChecking(proj, exercise, excluded))
}
});
var result = SandboxRunner.Run(new ProjRunnerSubmission
{
Id = slide.Id.ToString(),
ZipFileData = bytes,
ProjectFileName = exercise.CsprojFileName,
Input = "",
NeedRun = true
});
var isOk = result.Verdict.IsOneOf(Verdict.Ok, Verdict.MemoryLimit, Verdict.TimeLimit);
if (!isOk)
ReportSlideError(slide, "Exercise initial code verdict is not OK. RunResult = " + result);
else if (result.Verdict == Verdict.Ok && result.Output == "")
ReportSlideError(slide, "Exercise initial code (available to students) is solution!");
}
示例11: RemoveLibraries
public override void RemoveLibraries(DirectoryInfo outDirInfo) {
outDirInfo.GetFile("_CoverageWriter.pyd").Delete();
outDirInfo.GetFile("CoverageWriter.py").Delete();
}
示例12: RemoveLibraries
public override void RemoveLibraries(DirectoryInfo outDirInfo) {
outDirInfo.GetFile("CoverageWriter.UM.jar");
outDirInfo.GetFile("junit-4.8.2.jar");
outDirInfo.GetFile("Occf.Writer.UM.Java.dll");
}
示例13: CopyToDirectory
public static FileInfo CopyToDirectory(this FileInfo file, DirectoryInfo dir, bool overwrite)
{
var newFile = dir.GetFile(file.Name);
file.CopyTo(newFile.FullName, overwrite);
return newFile;
}
示例14: DownloadBucket
public static void DownloadBucket(string url, string targetPath, int parallelDownloads = 32)
{
Dictionary<string, string> etags;
var di = new DirectoryInfo(targetPath);
using (var s = di.GetFile("bucket.bson").Open(FileMode.OpenOrCreate))
{
using (var br = new BsonReader(s))
{
var se = new JsonSerializer();
etags = se.Deserialize<Dictionary<string, string>>(br) ?? new Dictionary<string, string>();
}
}
XDocument doc;
XNamespace xmlns = "http://s3.amazonaws.com/doc/2006-03-01/";
Console.Write("Loading S3 bucket... ");
while (true)
{
var xdoc = new XmlDocument();
xdoc.Load(url);
var xnr = new XmlNodeReader(xdoc);
xnr.MoveToContent();
doc = XDocument.Load(xnr);
Console.WriteLine("found {0} items", doc.Descendants(xmlns + "Contents").Count());
if (!doc.Descendants(xmlns + "Contents").Any())
{
continue;
}
break;
}
var actionsCompleted = 0;
var actions = new List<Tuple<string, string>>();
Action<Tuple<string, string>> downloadingAction = t =>
{
var etag = t.Item1;
var path = t.Item2;
var rpath = path.Replace('/', Path.DirectorySeparatorChar);
var fi = new FileInfo(Path.Combine(di.FullName + Path.DirectorySeparatorChar, rpath));
if (fi.Directory != null && !fi.Directory.Exists)
fi.Directory.Create();
else if (fi.Exists)
fi.Delete();
var b = new UriBuilder(url);
b.Path = b.Path.TrimEnd('/') + "/" + path;
while (true)
{
try
{
File.Move(Http.Download(b.Uri.ToString()), fi.FullName);
}
catch
{
continue;
}
break;
}
lock (etags)
{
etags[path] = etag;
actionsCompleted++;
Console.Write("Downloading... ({0}/{1}, {2}%)\r", actionsCompleted, actions.Count, Math.Round(100 * (float)actionsCompleted / actions.Count, 0));
}
};
foreach (var content in doc.Descendants(xmlns + "Contents"))
{
var xkey = content.Element(xmlns + "Key");
var xetag = content.Element(xmlns + "ETag");
if (xkey == null || xetag == null)
continue;
// Key as relative path
var relpath = xkey.Value;
// Compare etags
var etag = xetag.Value.Trim('"');
if (!etags.ContainsKey(relpath))
etags.Add(relpath, null);
if (etags[relpath] == etag)
continue; // File or directory not changed
// Local path
var rellpath = relpath.Replace('/', Path.DirectorySeparatorChar);
// Check if directory
if (relpath.EndsWith("/")) // is a directory
Directory.CreateDirectory(Path.Combine(di.FullName + Path.DirectorySeparatorChar, rellpath));
else
{
actions.Add(new Tuple<string, string>(etag, relpath));
//.........这里部分代码省略.........
示例15: ListFiles
private IEnumerable<FileInfo> ListFiles(DirectoryInfo projectRoot, IEnumerable<string> extraFiles)
{
yield return projectRoot.GetFile("Global.asax");
foreach (var fileName in extraFiles)
yield return projectRoot.GetFile(fileName);
}