当前位置: 首页>>代码示例>>C#>>正文


C# Directory.AddListing方法代码示例

本文整理汇总了C#中Directory.AddListing方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.AddListing方法的具体用法?C# Directory.AddListing怎么用?C# Directory.AddListing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Directory的用法示例。


在下文中一共展示了Directory.AddListing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NewFile

        /// <summary>
        /// Creates a new file within the file system.
        /// </summary>
        /// <param name="name">The name of the file to create.</param>
        /// <param name="parent">The parent directory of the new file.</param>
        /// <returns>The new file listing.</returns>
        public override File NewFile(String name, Directory parent)
        {
            if (FATType != FATTypeEnum.FAT32)
            {
                ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFileSystem.NewFile for non-FAT32 not supported!"));
            }
            if (parent == null)
            {
                ExceptionMethods.Throw(new Exceptions.NullReferenceException());
            }
            if (!(parent is FATDirectory))
            {
                ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFileSystem.NewFile parent directory must be of type FATDirectory!"));
            }

            //BasicConsole.WriteLine("Getting directory listings...");
            
            List listings = null;
            if (parent == null)
            {
                listings = GetRootDirectoryListings();
            }
            else
            {
                listings = parent.GetListings();
            }

            //BasicConsole.WriteLine("Got directory listings. Converting name...");

            name = name.ToUpper();

            //BasicConsole.WriteLine("Converted name. Checking if file exists...");

            bool exists = Directory.ListingExists(name, listings);

            //BasicConsole.WriteLine("Check done.");

            if (!exists)
            {
                //BasicConsole.WriteLine("Getting next free cluster...");
                UInt32 freeCluster = GetNextFreeCluster(2);
                //BasicConsole.WriteLine("Got next free. Clearing cluster...");
                WriteCluster(freeCluster, null);
                //BasicConsole.WriteLine("Cleared. Setting FAT entry...");
                SetFATEntryAndSave(freeCluster, GetFATEntryEOFValue(FATType));
                //BasicConsole.WriteLine("Set FAT entry. Creating new file...");
                File newFile = new FATFile(this, (FATDirectory)parent, name, 0, freeCluster);
                //BasicConsole.WriteLine("File created. Adding listing to parent...");
                if (parent == null)
                {
                    listings.Add(newFile);
                    //BasicConsole.WriteLine("Added. Writing listings...");
                    _rootDirectoryFAT32.WriteListings();
                }
                else
                {
                    parent.AddListing(newFile);
                    //BasicConsole.WriteLine("Added. Writing listings...");
                    parent.WriteListings();
                }
                //BasicConsole.WriteLine("Written listings.");
                return newFile;
            }
            else
            {
                ExceptionMethods.Throw(new IOException("Listing (directory/file) with specified name already exists!"));
            }
            return null;
        }
开发者ID:rmhasan,项目名称:FlingOS,代码行数:75,代码来源:FATFileSystem.cs


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