C# Path.GetDirectoryName的代码示例
通过代码示例来学习C# Path.GetDirectoryName方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
Path.GetDirectoryName是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.GetDirectoryName() 已经帮大家高亮显示了,大家可以重点学习Path.GetDirectoryName() 方法的写法,从而快速掌握该方法的应用。
Path.GetDirectoryName的代码示例1 - Initialize()
using System.IO; public virtual void Initialize() { string folderPath = Path.GetDirectoryName(this.databasePath); this.fileSystem.CreateDirectory(folderPath); using (SqliteConnection connection = new SqliteConnection(this.sqliteConnectionString)) { connection.Open(); using (SqliteCommand pragmaWalCommand = connection.CreateCommand()) { // Advantages of using WAL ("Write-Ahead Log") // 1. WAL is significantly faster in most scenarios. // 2. WAL provides more concurrency as readers do not block writers and a writer does not block readers. // Reading and writing can proceed concurrently. // 3. Disk I/O operations tends to be more sequential using WAL. // 4. WAL uses many fewer fsync() operations and is thus less vulnerable to problems on systems // where the fsync() system call is broken. // http://www.sqlite.org/wal.html pragmaWalCommand.CommandText = $"PRAGMA journal_mode=WAL;"; pragmaWalCommand.ExecuteNonQuery(); } using (SqliteCommand pragmaCacheSizeCommand = connection.CreateCommand()) { // If the argument N is negative, then the number of cache pages is adjusted to use approximately abs(N*1024) bytes of memory // -40000 => 40,000 * 1024 bytes => ~39MB pragmaCacheSizeCommand.CommandText = $"PRAGMA cache_size=-40000;"; pragmaCacheSizeCommand.ExecuteNonQuery(); } EventMetadata databaseMetadata = this.CreateEventMetadata(); using (SqliteCommand userVersionCommand = connection.CreateCommand()) { // The user_version pragma will to get or set the value of the user-version integer at offset 60 in the database header. // The user-version is an integer that is available to applications to use however they want. SQLite makes no use of the user-version itself. // https://sqlite.org/pragma.html#pragma_user_version userVersionCommand.CommandText = $"PRAGMA user_version;"; object userVersion = userVersionCommand.ExecuteScalar(); if (userVersion == null || Convert.ToInt64(userVersion) < 1) { userVersionCommand.CommandText = $"PRAGMA user_version=1;"; userVersionCommand.ExecuteNonQuery(); this.tracer.RelatedInfo($"{nameof(BlobSize)}.{nameof(this.Initialize)}: setting user_version to 1"); } else { databaseMetadata.Add("user_version", Convert.ToInt64(userVersion)); } } using (SqliteCommand pragmaSynchronousCommand = connection.CreateCommand()) { // GVFS uses the default value (FULL) to reduce the risks of corruption // http://www.sqlite.org/pragma.html#pragma_synchronous // (Note: This call is to retrieve the value of 'synchronous' and log it) pragmaSynchronousCommand.CommandText = $"PRAGMA synchronous;"; object synchronous = pragmaSynchronousCommand.ExecuteScalar(); if (synchronous != null) { databaseMetadata.Add("synchronous", Convert.ToInt64(synchronous)); } } this.tracer.RelatedEvent(EventLevel.Informational, $"{nameof(BlobSize)}_{nameof(this.Initialize)}_db_settings", databaseMetadata); using (SqliteCommand createTableCommand = connection.CreateCommand()) { // Use a BLOB for sha rather than a string to reduce the size of the database createTableCommand.CommandText = @"CREATE TABLE IF NOT EXISTS [BlobSizes] (sha BLOB, size INT, PRIMARY KEY (sha));"; createTableCommand.ExecuteNonQuery(); } } this.flushDataThread = new Thread(this.FlushDbThreadMain); this.flushDataThread.IsBackground = true; this.flushDataThread.Start(); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:83,代码来源:BlobSizes.cs
在Initialize()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例2 - CloneWithLocalCachePathWithinSrc()
using System.IO; [TestCase] public void CloneWithLocalCachePathWithinSrc() { string newEnlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); ProcessStartInfo processInfo = new ProcessStartInfo(GVFSTestConfig.PathToGVFS); processInfo.Arguments = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --local-cache-path {Path.Combine(newEnlistmentRoot, "src", ".gvfsCache")}"; processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.CreateNoWindow = true; processInfo.WorkingDirectory = Path.GetDirectoryName(this.Enlistment.EnlistmentRoot); processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; ProcessResult result = ProcessHelper.Run(processInfo); result.ExitCode.ShouldEqual(GVFSGenericError); result.Output.ShouldContain("'--local-cache-path' cannot be inside the src folder"); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:19,代码来源:CloneTests.cs
在CloneWithLocalCachePathWithinSrc()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例3 - DirectoryExists()
using System.IO; public override bool DirectoryExists(string path) { string parentDirectory = Path.GetDirectoryName(path); string targetName = Path.GetFileName(path); string output = this.RunProcess(string.Format("/C dir /A:d /B {0}", parentDirectory)); string[] directories = output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string directory in directories) { if (directory.Equals(targetName, FileSystemHelpers.PathComparison)) { return true; } } return false; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:20,代码来源:CmdRunner.cs
在DirectoryExists()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例4 - Execute()
using System.IO; public override bool Execute() { string templateFilePath = this.Template.ItemSpec; IDictionary
properties = ParseProperties(this.Template.GetMetadata("Properties")); string outputFileDirectory = Path.GetDirectoryName(this.OutputFile); if (!File.Exists(templateFilePath)) { this.Log.LogError("Failed to find template file '{0}'.", templateFilePath); return false; } // Copy the template to the destination to keep the same file mode bits/ACLs as the template File.Copy(templateFilePath, this.OutputFile, true); this.Log.LogMessage(MessageImportance.Low, "Reading template contents"); string template = File.ReadAllText(this.OutputFile); this.Log.LogMessage(MessageImportance.Normal, "Compiling template '{0}'", templateFilePath); string compiled = Compile(template, properties); if (!Directory.Exists(outputFileDirectory)) { this.Log.LogMessage(MessageImportance.Low, "Creating output directory '{0}'", outputFileDirectory); Directory.CreateDirectory(outputFileDirectory); } this.Log.LogMessage(MessageImportance.Normal, "Writing compiled template to '{0}'", this.OutputFile); File.WriteAllText(this.OutputFile, compiled); this.CompiledTemplate = new TaskItem(this.OutputFile, this.Template.CloneCustomMetadata()); return true; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:37,代码来源:CompileTemplatedFile.cs
在Execute()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例5 - FlushStagedQueues()
using System.IO; private void FlushStagedQueues() { using (ITracer activity = this.tracer.StartActivity("FlushStagedQueues", EventLevel.Informational)) { HashSet
deletedDirectories = new HashSet ( this.stagedDirectoryOperations .Where(d => d.Operation == DiffTreeResult.Operations.Delete) .Select(d => d.TargetPath.TrimEnd(Path.DirectorySeparatorChar)), GVFSPlatform.Instance.Constants.PathComparer); foreach (DiffTreeResult result in this.stagedDirectoryOperations) { string parentPath = Path.GetDirectoryName(result.TargetPath.TrimEnd(Path.DirectorySeparatorChar)); if (deletedDirectories.Contains(parentPath)) { if (result.Operation != DiffTreeResult.Operations.Delete) { EventMetadata metadata = new EventMetadata(); metadata.Add(nameof(result.TargetPath), result.TargetPath); metadata.Add(TracingConstants.MessageKey.WarningMessage, "An operation is intended to go inside of a deleted folder"); activity.RelatedError("InvalidOperation", metadata); } } else { this.DirectoryOperations.Enqueue(result); } } foreach (string filePath in this.stagedFileDeletes) { string parentPath = Path.GetDirectoryName(filePath); if (!deletedDirectories.Contains(parentPath)) { this.FileDeleteOperations.Enqueue(filePath); } } this.RequiredBlobs.CompleteAdding(); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:44,代码来源:DiffHelper.cs
在FlushStagedQueues()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例6 - TryFindNewBlobSizesRoot()
using System.IO; private bool TryFindNewBlobSizesRoot(ITracer tracer, string enlistmentRoot, out string newBlobSizesRoot) { newBlobSizesRoot = null; string localCacheRoot; string error; if (!RepoMetadata.Instance.TryGetLocalCacheRoot(out localCacheRoot, out error)) { tracer.RelatedError($"{nameof(DiskLayout13to14Upgrade_BlobSizes)}.{nameof(this.TryFindNewBlobSizesRoot)}: Could not read local cache root from repo metadata: {error}"); return false; } if (localCacheRoot == string.Empty) { // This is an old repo that was cloned prior to the shared cache // Blob sizes root should be
\.gvfs\databases\blobSizes newBlobSizesRoot = Path.Combine(enlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.Databases.Name, GVFSEnlistment.BlobSizesCacheName); } else { // This repo was cloned with a shared cache, and the blob sizes should be a sibling to the git objects root string gitObjectsRoot; if (!RepoMetadata.Instance.TryGetGitObjectsRoot(out gitObjectsRoot, out error)) { tracer.RelatedError($"{nameof(DiskLayout13to14Upgrade_BlobSizes)}.{nameof(this.TryFindNewBlobSizesRoot)}: Could not read git object root from repo metadata: {error}"); return false; } string cacheRepoFolder = Path.GetDirectoryName(gitObjectsRoot); newBlobSizesRoot = Path.Combine(cacheRepoFolder, GVFSEnlistment.BlobSizesCacheName); } return true; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:36,代码来源:DiskLayout13to14Upgrade_BlobSizes.cs
在TryFindNewBlobSizesRoot()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例7 - CreateAndConfigureProgramDataDirectories()
using System.IO; private void CreateAndConfigureProgramDataDirectories() { string serviceDataRootPath = Path.GetDirectoryName(this.serviceDataLocation); DirectorySecurity serviceDataRootSecurity = this.GetServiceDirectorySecurity(serviceDataRootPath); // Create GVFS.Service related directories (if they don't already exist) Directory.CreateDirectory(serviceDataRootPath, serviceDataRootSecurity); Directory.CreateDirectory(this.serviceDataLocation, serviceDataRootSecurity); // Ensure the ACLs are set correctly on any files or directories that were already created (e.g. after upgrading VFS4G) Directory.SetAccessControl(serviceDataRootPath, serviceDataRootSecurity); // Special rules for the Service.UI logs, as non-elevated users need to be be able to write this.CreateAndConfigureLogDirectory(GVFSPlatform.Instance.GetLogsDirectoryForGVFSComponent(GVFSConstants.Service.UIName)); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:18,代码来源:GVFSService.Windows.cs
在CreateAndConfigureProgramDataDirectories()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetDirectoryName的代码示例8 - Execute()
using System.IO; public override bool Execute() { this.Log.LogMessage(MessageImportance.Normal, "Creating GVFS constants file with minimum Git version '{0}' at '{1}'...", this.MinimumGitVersion, this.OutputFile); if (!TryParseVersion(this.MinimumGitVersion, out var version)) { this.Log.LogError("Failed to parse Git version '{0}'.", this.MinimumGitVersion); return false; } string outputDirectory = Path.GetDirectoryName(this.OutputFile); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } string template = @"// // This file is auto-generated by Scalar.Build.GenerateScalarConstants. // Any changes made directly in this file will be lost. // using GVFS.Common.Git; namespace GVFS.Common {{ public static partial class GVFSConstants {{ public static readonly GitVersion SupportedGitVersion = new GitVersion({0}, {1}, {2}, ""{3}"", {4}, {5}); public const string LibGit2LibraryName = ""{6}""; }} }}"; File.WriteAllText( this.OutputFile, string.Format( template, version.Major, version.Minor, version.Build, version.Platform, version.Revision, version.MinorRevision, this.LibGit2FileName)); return true; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:50,代码来源:GenerateGVFSConstants.cs
在Execute()方法中,Path的代码示例类中的GetDirectoryName的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的Path.GetDirectoryName方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。