C# DirectoryInfo.ToString的代码示例

通过代码示例来学习C# DirectoryInfo.ToString方法

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


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

DirectoryInfo.ToString的代码示例1 - TakeOwnDirectory()

    using System.IO;
        public static void TakeOwnDirectory(string path)
        {
            DirectoryInfo directoryInfo = new(path);
            DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();

            directorySecurity.SetOwner(WindowsIdentity.GetCurrent().User);

            Privilege p = new(Privilege.TakeOwnership);
            bool ownershipTaken = false;
            try
            {
                p.Enable();

                new DirectoryInfo(path).SetAccessControl(directorySecurity);
                ownershipTaken = true;
            }
            catch (Privileges.PrivilegeNotHeldException e)
            {
                Console.WriteLine("Failed to assign privileges. " + e.ToString());
            }
            finally
            {
                p.Revert();
            }

            if (ownershipTaken)
            {
                AdjustPermissionsForDirectory(path);

                foreach (string subFile in (System.Collections.Generic.IEnumerable)Directory.EnumerateFiles(path))
                {
                    TakeOwnFile(subFile);
                }

                foreach (string subDir in (System.Collections.Generic.IEnumerable)Directory.EnumerateDirectories(path))
                {
                    TakeOwnDirectory(subDir);
                }
            }
        }
    

开发者ID:gus33000,项目名称:UUPMediaCreator,代码行数:41,代码来源:TakeOwn.cs

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

DirectoryInfo.ToString的代码示例2 - CreateFile()

    using System.IO;

        protected string CreateFile(DirectoryInfo dInfo, string fileName)
        {
            int lineCount = 10;
            string fullName = dInfo == null ? fileName : dInfo.FullName + Path.DirectorySeparatorChar + fileName;

            using (StreamWriter writer = new StreamWriter(File.Create(fullName)))
            {
                for (int i = 1; i <= lineCount; ++i)
                {
                    writer.WriteLine("Line number " + i.ToString("D3") + " of File " + fullName);
                }

                writer.Flush();
            }

            return fullName;
        }
    

开发者ID:zarunbal,项目名称:LogExpert,代码行数:19,代码来源:RolloverHandlerTestBase.cs

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

DirectoryInfo.ToString的代码示例3 - GetProperFilePathCapitalization()

    using System.IO;

        private static string GetProperFilePathCapitalization(string filename)
        {
            StringBuilder builder = new StringBuilder();
            FileInfo fileInfo = new FileInfo(filename);
            DirectoryInfo dirInfo = fileInfo.Directory;
            GetProperDirectoryCapitalization(dirInfo, null, ref builder);
            string properFileName = fileInfo.Name;
            if (dirInfo != null && dirInfo.Exists)
            {
                foreach (var fsInfo in dirInfo.EnumerateFileSystemInfos())
                {
                    if (((fsInfo.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
                        && string.Compare(fsInfo.Name, fileInfo.Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        properFileName = fsInfo.Name;
                        break;
                    }
                }
            }
            return Path.Combine(builder.ToString(), properFileName);
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:23,代码来源:PathUtil.cs

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

DirectoryInfo.ToString的代码示例4 - Explorer()

    using System.IO;

        static void Explorer()
        {
            string explorerFile = "";
            try
            {
                Guid IPropertyStoreGuid = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");

                PropertySystemNativeMethods.PSGetPropertyKeyFromName("System.Comment", out PropertyKey key);

                DirectoryInfo di = new DirectoryInfo(targetDirectory);
                int count = 0;
                bool done = false;
                while (!done)
                {
                    foreach (FileInfo file in di.GetFiles())
                    {
                        explorerFile = file.Name;
                        count++;
                        HResult hr = (HResult)SHGetPropertyStoreFromParsingName(file.FullName, IntPtr.Zero,
                        GETPROPERTYSTOREFLAGS.GPS_READWRITE, ref IPropertyStoreGuid, out IPropertyStore ps);

                        if (hr == HResult.Ok)
                        {
                            try
                            {
                                PropVariant val = new PropVariant();
                                hr = ps.GetValue(key, val);
                                if (hr == HResult.Ok)
                                {
                                    var sValue = val.ToString();

                                    if (count % 30 == 0)
                                    {
                                        PropVariant value = new PropVariant("test comment");
                                        hr = ps.SetValue(key, value);
                                        if (hr == HResult.Ok)
                                        {
                                            hr = ps.Commit();
                                            if (hr == HResult.Ok)
                                                LogLine(3, $"Explorer Read '{sValue}' and updated");
                                            else if ((int)hr > 0)
                                            {
                                                LogLine(2, $"Commit for {explorerFile} returned {hr:X}");
                                            }
                                            else
                                                throw new Exception($"Commit failed with 0x{hr:X}");
                                        }
                                        else
                                            throw new Exception($"SetValue failed with 0x{hr:X}");
                                    }
                                    else
                                        LogLine(3, $"Explorer Read '{sValue}'");
                                }
                                else if ((uint)hr == 0x80030021)
                                {
                                    LogLine(2, $"GetValue for {explorerFile} failed with STG_E_LOCKVIOLATION");
                                    IncrementExplorerFail();
                                }
                                else
                                    throw new Exception($"GetValue failed with 0x{hr:X}");

                                done = IncrementExplorer();
                                if (done)
                                    break;
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(ps);  // optional GC preempt
                            }
                        }
                        else if ((uint)hr == 0x80030021)
                        {
                            LogLine(2, $"Explorer Open failed on '{explorerFile}' with lock violation 0x{hr:X}");
                            IncrementExplorerFail();
                        }
                        else
                            throw new Exception($"Open failed with 0x{hr:X}");
                    }
                }
            }
            catch (Exception ex)
            {
                LogLine(1, $"Explorer terminated for '{explorerFile}': {ex}");
                IncrementExplorerTerminated();
            }
        }
    

开发者ID:Dijji,项目名称:FileMeta,代码行数:88,代码来源:Program.cs

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

DirectoryInfo.ToString的代码示例5 - SetException()

    using System.IO;

        private void SetException(Exception exception)
        {
            string path = Log.CurrentLogDirectory;
            var directory = new DirectoryInfo(path);
            var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();

            var websiteUrl = exception switch
                {
                    FlowPluginException pluginException =>GetIssuesUrl(pluginException.Metadata.Website),
                    _ => Constant.IssuesUrl
                };
                

            var paragraph = Hyperlink("Please open new issue in: ", websiteUrl);
            paragraph.Inlines.Add($"1. upload log file: {log.FullName}\n");
            paragraph.Inlines.Add($"2. copy below exception message");
            ErrorTextbox.Document.Blocks.Add(paragraph);

            StringBuilder content = new StringBuilder();
            content.AppendLine(ErrorReporting.RuntimeInfo());
            content.AppendLine(ErrorReporting.DependenciesInfo());
            content.AppendLine($"Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
            content.AppendLine("Exception:");
            content.AppendLine(exception.ToString());
            paragraph = new Paragraph();
            paragraph.Inlines.Add(content.ToString());
            ErrorTextbox.Document.Blocks.Add(paragraph);
        }
    

开发者ID:Flow-Launcher,项目名称:Flow.Launcher,代码行数:30,代码来源:ReportWindow.xaml.cs

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

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