C# Path.GetFullPath的代码示例

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

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


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

Path.GetFullPath的代码示例1 - GetCloneRoot()

    using System.IO;

        private string GetCloneRoot(out string fullEnlistmentRootPathParameter)
        {
            fullEnlistmentRootPathParameter = null;

            try
            {
                string repoName = this.RepositoryURL.Substring(this.RepositoryURL.LastIndexOf('/') + 1);
                fullEnlistmentRootPathParameter =
                    string.IsNullOrWhiteSpace(this.EnlistmentRootPathParameter)
                    ? Path.Combine(Environment.CurrentDirectory, repoName)
                    : this.EnlistmentRootPathParameter;

                fullEnlistmentRootPathParameter = Path.GetFullPath(fullEnlistmentRootPathParameter);

                string errorMessage;
                string enlistmentRootPath;
                if (!GVFSPlatform.Instance.FileSystem.TryGetNormalizedPath(fullEnlistmentRootPathParameter, out enlistmentRootPath, out errorMessage))
                {
                    this.ReportErrorAndExit("Unable to determine normalized path of clone root: " + errorMessage);
                    return null;
                }

                return enlistmentRootPath;
            }
            catch (IOException e)
            {
                this.ReportErrorAndExit("Unable to determine clone root: " + e.ToString());
                return null;
            }
        }
    

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

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

Path.GetFullPath的代码示例2 - TryValidatePath()

    using System.IO;

        private bool TryValidatePath(string path, out string validatedPath, ITracer tracer)
        {
            try
            {
                validatedPath = Path.GetFullPath(path);
                return true;
            }
            catch (Exception ex)
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Exception", ex.ToString());
                metadata.Add("Path", path);

                tracer.RelatedError(metadata, $"{nameof(this.TryValidatePath)}: {path}. {ex.ToString()}");
            }

            validatedPath = null;
            return false;
        }
    

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

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

Path.GetFullPath的代码示例3 - ValidatePathParameter()

    using System.IO;

        protected void ValidatePathParameter(string path)
        {
            if (!string.IsNullOrWhiteSpace(path))
            {
                try
                {
                    Path.GetFullPath(path);
                }
                catch (Exception e)
                {
                    this.ReportErrorAndExit("Invalid path: '{0}' ({1})", path, e.Message);
                }
            }
        }
    

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

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

Path.GetFullPath的代码示例4 - GetVersionFromFile()

    using System.IO;

        /// 
        /// Extracts value retrieved from the file.
        /// If the file is an assembly then the assembly version is returned.
        /// If the file is an MSI then the product version is returned.
        /// If the file is a native binary then file version is returned.
        /// 
        /// 
        /// Attempt to extract the assembly version may fail because the dll/exe file may not be an assembly
        /// or because it can be in the wrong assembly format (x64 vs x86). In any case the method will fall back to
        /// the file version.
        /// The file path.
        /// 
        static public Version GetVersionFromFile(string filePath)
        {
            string version = null;

            try
            {
                var file = IO.Path.GetFullPath(filePath);
                if (file.EndsWith(".msi", ignoreCase: true))
                {
                    using (var database = new Database(file, DatabaseOpenMode.ReadOnly))
                    {
                        using (var view = database.OpenView(database.Tables["Property"].SqlSelectString))
                        {
                            view.Execute();
                            version = view.Where(r => r.GetString("Property") == "ProductVersion")
                                          .Select(r => r.GetString("Value"))
                                          .FirstOrDefault();
                        }
                    }
                }
                else
                {
                    version = FileVersionInfo.GetVersionInfo(filePath).FileVersion;
                    if (file.EndsWith(".dll", ignoreCase: true) || file.EndsWith(".exe", ignoreCase: true))
                    {
                        try
                        {
                            version = System.Reflection.Assembly.ReflectionOnlyLoadFrom(file).GetName().Version.ToString();
                        }
                        catch { }
                    }
                }
            }
            catch { }

            if (version == null)
                throw new Exception("Cannot extract version from '" + filePath + "'");

            return new Version(version);
        }
    

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

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

Path.GetFullPath的代码示例5 - BuildCmd()

    using System.IO;

        /// 
        /// Builds the WiX source file and generates batch file capable of building
        /// WiX/MSI bootstrapper with WiX toolset.
        /// 
        /// The project.
        /// The path to the batch file to be created.
        /// Wix compiler/linker cannot be found
        public static string BuildCmd(Bundle project, string path = null)
        {
            if (path == null)
                path = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, "Build_" + project.OutFileName) + ".cmd");

            path = path.ExpandEnvVars();

            //System.Diagnostics.Debug.Assert(false);
            string wixLocationEnvVar = $"set WixLocation={WixLocation}" + Environment.NewLine;
            string compiler = Utils.PathCombine(WixLocation, "candle.exe");
            string linker = Utils.PathCombine(WixLocation, "light.exe");
            string batchFile = path;

            if (!IO.File.Exists(compiler) || !IO.File.Exists(linker))
            {
                Compiler.OutputWriteLine("Wix binaries cannot be found. Expected location is " + IO.Path.GetDirectoryName(compiler));
                throw new ApplicationException("Wix compiler/linker cannot be found");
            }
            else
            {
                string wxsFile = BuildWxs(project);

                if (!project.SourceBaseDir.IsEmpty())
                    Environment.CurrentDirectory = project.SourceBaseDir;

                string objFile = IO.Path.ChangeExtension(wxsFile, ".wixobj");
                string pdbFile = IO.Path.ChangeExtension(wxsFile, ".wixpdb");

                string extensionDlls = "";
                // note we need to avoid possible duplications cause by non expanded envars
                // %wix_location%\ext.dll vs c:\Program Files\...\ext.dll
                foreach (string dll in project.WixExtensions.DistinctBy(x => x.ExpandEnvVars()))
                    extensionDlls += " -ext \"" + dll + "\"";

                string wxsFiles = "";
                foreach (string file in project.WxsFiles.Distinct())
                    wxsFiles += " \"" + file + "\"";

                var candleOptions = CandleOptions + " " + project.CandleOptions;

                string batchFileContent = wixLocationEnvVar + "\"" + compiler + "\" " + candleOptions + " " + extensionDlls +
                                          " \"" + wxsFile + "\" ";

                string outDir = null;
                if (wxsFiles.IsNotEmpty())
                {
                    batchFileContent += wxsFiles;
                    outDir = IO.Path.GetDirectoryName(wxsFile);
                    // if multiple files are specified candle expect a path for the -out switch
                    // or no path at all (use current directory)
                    // note the '\' character must be escaped twice: as a C# string and as a CMD char
                    if (outDir.IsNotEmpty())
                        batchFileContent += $" -out \"{outDir}\\\\\"";
                }
                else
                    batchFileContent += $" -out \"{objFile}\"";

                batchFileContent += "\r\n";

                string fragmentObjectFiles = project.WxsFiles
                                             .Distinct()
                                             .JoinBy(" ", file => "\"" + outDir.PathCombine(IO.Path.GetFileNameWithoutExtension(file)) + ".wixobj\"");

                string lightOptions = LightOptions + " " + project.LightOptions;

                if (fragmentObjectFiles.IsNotEmpty())
                    lightOptions += " " + fragmentObjectFiles;

                if (path.IsNotEmpty())
                    lightOptions += " -out \"" + IO.Path.ChangeExtension(objFile, ".exe") + "\"";

                batchFileContent += "\"" + linker + "\" " + lightOptions + " \"" + objFile + "\" " + extensionDlls + " -cultures:" + project.Language + "\r\npause";

                batchFileContent = batchFileContent.ExpandEnvVars();

                using (var sw = new IO.StreamWriter(batchFile))
                    sw.Write(batchFileContent);
            }

            return path;
        }
    

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

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

Path.GetFullPath的代码示例6 - GetFiles()

    using System.IO;

        /// 
        /// Analyses  and returns all files matching .
        /// 
        /// The base directory for file analysis. It is used in conjunction with
        /// relative .Though  takes precedence if it is an absolute path.
        /// Array of s.
        public File[] GetFiles(string baseDirectory)
        {
            if (IO.Path.IsPathRooted(Directory))
                baseDirectory = Directory;
            if (baseDirectory.IsEmpty())
                baseDirectory = Environment.CurrentDirectory;

            baseDirectory = IO.Path.GetFullPath(baseDirectory);

            string rootDirPath;
            if (IO.Path.IsPathRooted(Directory))
                rootDirPath = Directory;
            else
                rootDirPath = Utils.PathCombine(baseDirectory, Directory);

            var files = new List();
            var excludeWildcards = new List();

            foreach (string file in IO.Directory.GetFiles(rootDirPath, IncludeMask))
            {
                bool ignore = false;

                if (!ignore && Filter(file))
                {
                    var filePath = IO.Path.GetFullPath(file);

                    var item = new File(filePath)
                    {
                        Feature = this.Feature,
                        Features = this.Features,
                        AttributesDefinition = this.AttributesDefinition,
                        Attributes = this.Attributes.Clone()
                    };

                    OnProcess?.Invoke(item);

                    files.Add(item);
                }
            }
            return files.ToArray();
        }
    

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

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

Path.GetFullPath的代码示例7 - DeleteIfExists()

    using System.IO;

        /// 
        /// Deletes File/Directory from by the specified path if it exists.
        /// 
        /// The path.
        /// if set to false handle all exceptions silently.
        /// 
        public static string DeleteIfExists(this string path, bool @throw = false)
        {
            void deleteFile(string file)
            {
                try
                {
                    var fullPath = IO.Path.GetFullPath(file);
                    if (IO.File.Exists(fullPath))
                        IO.File.Delete(fullPath);
                }
                catch
                {
                    if (@throw)
                        throw;
                }
            }

            void deleteDir(string file)
            {
                try
                {
                    var fullPath = IO.Path.GetFullPath(file);
                    if (IO.Directory.Exists(fullPath))
                        IO.Directory.Delete(fullPath);
                }
                catch
                {
                    if (@throw)
                        throw;
                }
            }

            if (path.IsDirectory())
            {
                IO.Directory.GetFiles(path, "*", IO.SearchOption.AllDirectories)
                            .ForEach(deleteFile);

                IO.Directory.GetDirectories(path, "*", IO.SearchOption.AllDirectories)
                            .OrderByDescending(x => x)
                            .ForEach(deleteDir);

                deleteDir(path);
            }
            else
            {
                deleteFile(path);
            }

            return path;
        }
    

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

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

Path.GetFullPath的代码示例8 - GetAllItems()

    using System.IO;

        /// 
        /// Analyses  and returns all files (including subdirectories) matching .
        /// 
        /// The base directory for file analysis. It is used in conjunction with
        /// relative . Though  takes precedence if it is an absolute path.
        /// Array of  instances, which are either  or/and  objects.
        /// Parent Wix# directory
        public WixEntity[] GetAllItems(string baseDirectory, Dir parentWixDir = null)
        {
            if (IO.Path.IsPathRooted(Directory))
                baseDirectory = Directory;
            if (baseDirectory.IsEmpty())
                baseDirectory = Environment.CurrentDirectory;

            baseDirectory = IO.Path.GetFullPath(baseDirectory);

            string rootDirPath;
            if (IO.Path.IsPathRooted(Directory))
                rootDirPath = Directory;
            else
                rootDirPath = Utils.PathCombine(baseDirectory, Directory);

            void AgregateSubDirs(Dir parentDir, string dirPath)
            {
                foreach (var subDirPath in IO.Directory.GetDirectories(dirPath))
                {
                    var dirName = IO.Path.GetFileName(subDirPath);

                    Dir subDir = parentDir.Dirs.FirstOrDefault(dir => dir.Name.SameAs(dirName, ignoreCase: true));

                    if (subDir == null)
                    {
                        subDir = new Dir(dirName);
                        parentDir.AddDir(subDir);
                    }

                    subDir.AddFeatures(this.ActualFeatures);
                    subDir.AddDirFileCollection(
                                                new DirFiles(IO.Path.Combine(subDirPath, this.IncludeMask))
                                                {
                                                    Feature = this.Feature,
                                                    Features = this.Features,
                                                    AttributesDefinition = this.AttributesDefinition,
                                                    Attributes = this.Attributes,
                                                    Filter = this.Filter,
                                                    OnProcess = this.OnProcess
                                                });

                    AgregateSubDirs(subDir, subDirPath);
                }
            };

            var result = new List
            {
                new DirFiles(IO.Path.Combine(rootDirPath, this.IncludeMask))
                {
                    Feature = this.Feature,
                    Features = this.Features,
                    AttributesDefinition = this.AttributesDefinition,
                    Attributes = this.Attributes.Clone(),
                    Filter = this.Filter,
                    OnProcess = this.OnProcess
                }
            };

            if (!IO.Directory.Exists(rootDirPath))
                throw new IO.DirectoryNotFoundException(rootDirPath);

            foreach (var subDirPath in System.IO.Directory.GetDirectories(rootDirPath))
            {
                var dirName = IO.Path.GetFileName(subDirPath);

                var subDir = parentWixDir?.Dirs.FirstOrDefault(dir => dir.Name.SameAs(dirName, ignoreCase: true));

                if (subDir == null)
                {
                    subDir = new Dir(dirName);
                    result.Add(subDir);
                }

                subDir.AddFeatures(this.ActualFeatures);
                subDir.AddDirFileCollection(
                                            new DirFiles(IO.Path.Combine(subDirPath, this.IncludeMask))
                                            {
                                                Feature = this.Feature,
                                                Features = this.Features,
                                                AttributesDefinition = this.AttributesDefinition,
                                                Attributes = this.Attributes,
                                                Filter = this.Filter,
                                                OnProcess = this.OnProcess
                                            });

                AgregateSubDirs(subDir, subDirPath);
            }

            return result.ToArray();
        }
    

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

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

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