C# Path.GetExtension的代码示例

通过代码示例来学习C# Path.GetExtension方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


Path.GetExtension是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.GetExtension() 已经帮大家高亮显示了,大家可以重点学习Path.GetExtension() 方法的写法,从而快速掌握该方法的应用。

Path.GetExtension的代码示例1 - GetPackFilesInfo()

    using System.IO;

        // public only for unit tests
        public void GetPackFilesInfo(out int count, out long size, out bool hasKeep)
        {
            count = 0;
            size = 0;
            hasKeep = false;

            foreach (DirectoryItemInfo info in this.Context.FileSystem.ItemsInDirectory(this.Context.Enlistment.GitPackRoot))
            {
                string extension = Path.GetExtension(info.Name);

                if (string.Equals(extension, ".pack", GVFSPlatform.Instance.Constants.PathComparison))
                {
                    count++;
                    size += info.Length;
                }
                else if (string.Equals(extension, ".keep", GVFSPlatform.Instance.Constants.PathComparison))
                {
                    hasKeep = true;
                }
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:24,代码来源:GitMaintenanceStep.cs

在GetPackFilesInfo()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例2 - CleanStaleIdxFiles()

    using System.IO;

        // public only for unit tests
        public List CleanStaleIdxFiles(out int numDeletionBlocked)
        {
            List packDirContents = this.Context
                                                          .FileSystem
                                                          .ItemsInDirectory(this.Context.Enlistment.GitPackRoot)
                                                          .ToList();

            numDeletionBlocked = 0;
            List deletedIdxFiles = new List();

            // If something (probably VFS for Git) has a handle open to a ".idx" file, then
            // the 'git multi-pack-index expire' command cannot delete it. We should come in
            // later and try to clean these up. Count those that we are able to delete and
            // those we still can't.

            foreach (DirectoryItemInfo info in packDirContents)
            {
                if (string.Equals(Path.GetExtension(info.Name), ".idx", GVFSPlatform.Instance.Constants.PathComparison))
                {
                    string pairedPack = Path.ChangeExtension(info.FullName, ".pack");

                    if (!this.Context.FileSystem.FileExists(pairedPack))
                    {
                        if (this.Context.FileSystem.TryDeleteFile(info.FullName))
                        {
                            deletedIdxFiles.Add(info.Name);
                        }
                        else
                        {
                            numDeletionBlocked++;
                        }
                    }
                }
            }

            return deletedIdxFiles;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:40,代码来源:PackfileMaintenanceStep.cs

在CleanStaleIdxFiles()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例3 - UpdateKeepPacks()

    using System.IO;

        /// 
        /// Ensure the prefetch pack with most-recent timestamp has an associated
        /// ".keep" file. This prevents any Git command from deleting the pack.
        ///
        /// Delete the previous ".keep" file(s) so that pack can be deleted when they
        /// are not the most-recent pack.
        /// 
        private void UpdateKeepPacks()
        {
            if (!this.TryGetMaxGoodPrefetchTimestamp(out long maxGoodTimeStamp, out string error))
            {
                return;
            }

            string prefix = $"prefetch-{maxGoodTimeStamp}-";

            DirectoryItemInfo info = this.Context
                                         .FileSystem
                                         .ItemsInDirectory(this.Context.Enlistment.GitPackRoot)
                                         .Where(item => item.Name.StartsWith(prefix)
                                                        && string.Equals(Path.GetExtension(item.Name), ".pack", GVFSPlatform.Instance.Constants.PathComparison))
                                         .FirstOrDefault();
            if (info == null)
            {
                this.Context.Tracer.RelatedWarning(this.CreateEventMetadata(), $"Could not find latest prefetch pack, starting with {prefix}");
                return;
            }

            string newKeepFile = Path.ChangeExtension(info.FullName, ".keep");

            if (!this.Context.FileSystem.TryWriteAllText(newKeepFile, string.Empty))
            {
                this.Context.Tracer.RelatedWarning(this.CreateEventMetadata(), $"Failed to create .keep file at {newKeepFile}");
                return;
            }

            foreach (string keepFile in this.Context
                                     .FileSystem
                                     .ItemsInDirectory(this.Context.Enlistment.GitPackRoot)
                                     .Where(item => item.Name.EndsWith(".keep"))
                                     .Select(item => item.FullName))
            {
                if (!keepFile.Equals(newKeepFile))
                {
                    this.Context.FileSystem.TryDeleteFile(keepFile);
                }
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:50,代码来源:PrefetchStep.cs

在UpdateKeepPacks()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例4 - PrefetchCleansUpStalePrefetchLock()

    using System.IO;

        [TestCase, Order(11)]
        public void PrefetchCleansUpStalePrefetchLock()
        {
            this.Enlistment.Prefetch("--commits");
            this.PostFetchStepShouldComplete();
            string prefetchCommitsLockFile = Path.Combine(this.Enlistment.GetObjectRoot(this.fileSystem), "pack", PrefetchCommitsAndTreesLock);
            prefetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
            this.fileSystem.WriteAllText(prefetchCommitsLockFile, this.Enlistment.EnlistmentRoot);
            prefetchCommitsLockFile.ShouldBeAFile(this.fileSystem);

            this.fileSystem
                .EnumerateDirectory(this.Enlistment.GetPackRoot(this.fileSystem))
                .Split()
                .Where(file => string.Equals(Path.GetExtension(file), ".keep", FileSystemHelpers.PathComparison))
                .Count()
                .ShouldEqual(1, "Incorrect number of .keep files in pack directory");

            this.Enlistment.Prefetch("--commits");
            this.PostFetchStepShouldComplete();
            prefetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:23,代码来源:PrefetchVerbTests.cs

在PrefetchCleansUpStalePrefetchLock()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例5 - AddExecuteCommand()

    using System.IO;

        private static void AddExecuteCommand(IO.TextWriter writer, Package package, string arguments, string exitCode)
        {
            // Combine arguments and expand environment variables.
            arguments = AppendArgument(package.Arguments, arguments);
            AddExpandEnvStringsCommand(writer, ref arguments);

            // Extract only filename from the path.
            var fileName = IO.Path.GetFileName(package.FileName);

            if (package.UseShellExecute)
            {
                string text = $"ExecShell \"\" \"{PluginsDir}\\{fileName}\"";
                if (arguments != null)
                {
                    text = AppendArgument(text, $"\"{arguments}\"");
                }
                writer.WriteLine(text);
                writer.WriteLine("Sleep 2000");
            }
            else
            {
                var extension = IO.Path.GetExtension(fileName)?.ToUpper() ?? string.Empty;

                string text;
                switch (extension)
                {
                    case ".MSI":
                        text = $"\"$%WINDIR%\\System32\\msiexec.exe\" /I \"{PluginsDir}\\{fileName}\"";
                        text = AppendArgument(text, arguments);
                        break;

                    case ".PS1":
                        text = $"\"powershell.exe\" -NoProfile -ExecutionPolicy Bypass -File \"{PluginsDir}\\{fileName}\"";
                        text = AppendArgument(text, arguments);
                        break;

                    case ".BAT":
                    case ".CMD":
                        text = $"\"$%WINDIR%\\System32\\cmd.exe\" /C \"{PluginsDir}\\{fileName}\"";
                        text = AppendArgument(text, arguments);
                        break;

                    case ".VBS":
                    case ".JS":
                        text = $"\"$%WINDIR%\\System32\\wscript.exe\" \"{PluginsDir}\\{fileName}\"";
                        text = AppendArgument(text, arguments);
                        break;

                    // case ".EXE":
                    default:
                        text = $"\"{PluginsDir}\\{fileName}\"";
                        text = AppendArgument(text, arguments);
                        break;
                }

                if (package.CreateNoWindow)
                {
                    text = $"nsExec::Exec '{text}'";
                    writer.WriteLine(text);
                    writer.WriteLine($"Pop {exitCode}");
                }
                else
                {
                    text = $"ExecWait '{text}'";
                    text = AppendArgument(text, exitCode);
                    writer.WriteLine(text);
                }
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:71,代码来源:NsisBootstrapper.cs

在AddExecuteCommand()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例6 - SaveScene()

    using System.IO;

        private void SaveScene(string FileName, Scene scene, List Meshes)
        {
            using (var v = new AssimpContext())
            {
                string ext = System.IO.Path.GetExtension(FileName);

                string formatID = "collada";
                if (ext == ".obj")
                    formatID = "obj";
                if (ext == ".3ds")
                    formatID = "3ds";
                if (ext == ".dae")
                    formatID = "collada";
                if (ext == ".ply")
                    formatID = "ply";

                bool ExportSuccessScene = v.ExportFile(scene, FileName, formatID, PostProcessSteps.FlipUVs);
                if (ExportSuccessScene)
                {
                    if (ext == ".dae")
                        WriteExtraSkinningInfo(FileName, scene, Meshes);

                    MessageBox.Show($"Exported {FileName} Successfuly!");
                }
                else
                    MessageBox.Show($"Failed to export {FileName}!");
            }

        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:31,代码来源:AssimpSaver.cs

在SaveScene()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例7 - CalculateHashes()

    using System.IO;

        private static void CalculateHashes()
        {
            string dir = Path.Combine(Runtime.ExecutableDir, "Hashes");
            if (!Directory.Exists(dir))
                return;

            foreach (var file in Directory.GetFiles(dir))
            {
                if (Utils.GetExtension(file) != ".txt")
                    continue;

                foreach (string hashStr in File.ReadAllLines(file))
                {
                    CheckHash(hashStr);
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:19,代码来源:BCSVParse.cs

在CalculateHashes()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetExtension的代码示例8 - GetTextures()

    using System.IO;

        public Dictionary GetTextures()
        {
            Dictionary textures = new Dictionary();

            if (File.Exists(FilePath))
            {
                string folder = Path.GetDirectoryName(FilePath);
                foreach (var file in Directory.GetFiles(folder))
                {
                    try
                    {
                        if (Utils.GetExtension(file) == ".bflim")
                        {
                            BFLIM bflim = (BFLIM)STFileLoader.OpenFileFormat(file);
                            if (!textures.ContainsKey(bflim.FileName))
                                textures.Add(bflim.FileName, bflim);
                        }
                        if (Utils.GetExtension(file) == ".bntx")
                        {
                            BNTX bntx = (BNTX)STFileLoader.OpenFileFormat(file);
                            foreach (var tex in bntx.Textures)
                            {
                                if (!textures.ContainsKey(tex.Key))
                                    textures.Add(tex.Key, tex.Value);
                            }

                            string fileName = Path.GetFileName(file);
                            if (!header.TextureManager.BinaryContainers.ContainsKey(fileName))
                                header.TextureManager.BinaryContainers.Add(fileName, bntx);
                        }
                    }
                    catch (Exception ex)
                    {
                        STErrorDialog.Show($"Failed to load texture {file}. ", "Layout Editor", ex.ToString());
                    }
                }
            }

            foreach (var archive in PluginRuntime.SarcArchives)
            {
                foreach (var file in archive.Files)
                {
                    try
                    {
                        if (Utils.GetExtension(file.FileName) == ".bntx")
                        {
                            BNTX bntx = (BNTX)file.OpenFile();
                            file.FileFormat = bntx;
                            foreach (var tex in bntx.Textures)
                                if (!textures.ContainsKey(tex.Key))
                                    textures.Add(tex.Key, tex.Value);

                            if (!header.TextureManager.BinaryContainers.ContainsKey($"{archive.FileName}.bntx"))
                                header.TextureManager.BinaryContainers.Add($"{archive.FileName}.bntx", bntx);
                        }
                        if (Utils.GetExtension(file.FileName) == ".bflim")
                        {
                            BFLIM bflim = (BFLIM)file.OpenFile();
                            string name = bflim.FileName;
                            if (archive is SARC)
                            {
                                if (((SARC)archive).sarcData.HashOnly)
                                {
                                    var sarcEntry = file as SARC.SarcEntry;

                                    //Look through all textures and find a hash match
                                    name = sarcEntry.TryGetHash(header.Textures, "timg");
                                    name = Path.GetFileName(name);
                                }
                            }

                            file.FileFormat = bflim;
                            if (!textures.ContainsKey(bflim.FileName))
                                textures.Add(name, bflim);
                        }
                    }
                    catch (Exception ex)
                    {
                        STErrorDialog.Show($"Failed to load texture {file.FileName}. ", "Layout Editor", ex.ToString());
                    }
                }

                if (!header.TextureManager.ArchiveFile.ContainsKey(archive.FileName))
                    header.TextureManager.ArchiveFile.Add(archive.FileName, archive);
            }

            return textures;
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:90,代码来源:BFLYT.cs

在GetTextures()方法中,Path的代码示例类中的GetExtension的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的Path.GetExtension方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。