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


C# FOS_System.Substring方法代码示例

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


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

示例1: RemoveMappingPrefix

 /// <summary>
 /// Removes the mapping's prefix from the specified path.
 /// </summary>
 /// <param name="aPath">The path to remove the prefix from.</param>
 /// <returns>The path without the prefix.</returns>
 public FOS_System.String RemoveMappingPrefix(FOS_System.String aPath)
 {
     return aPath.Substring(prefix.length, aPath.length - prefix.length);
 }
开发者ID:rmhasan,项目名称:FlingOS,代码行数:9,代码来源:FileSystemMapping.cs

示例2: CopyFile

        /// <summary>
        /// Copies the specified file.
        /// </summary>
        /// <param name="srcFile">The file to copy.</param>
        /// <param name="dst">The path to copy to.</param>
        private void CopyFile(File srcFile, FOS_System.String dst)
        {
            //If source file is null, it means it wasn't found by the caller (or some
            //  other error but we will assume not found since that is the expected use 
            //  case from the other overload of CopyFile).
            if(srcFile == null)
            {
                console.WriteLine("Source file not found!");
                return;
            }

            //Attempt to open the destination file.
            File dstFile = File.Open(dst);
            //If opening failed, the file was not found so either the path
            //  was invalid or the file does not currently exist. We assume
            //  the latter. If the path is invalid, it will be caught later.
            if (dstFile == null)
            {
                //console.WriteLine("Creating destination file...");
                //If the path is invalid because of path mapping, it will be 
                //  caught here.
                FileSystemMapping mapping = FileSystemManager.GetMapping(dst);
                if (mapping == null)
                {
                    console.WriteLine("Destination file system not found!");
                    return;
                }

                //+1 to include the slash in dir name
                int lastIdx = dst.LastIndexOf(FileSystemManager.PathDelimiter) + 1;
                FOS_System.String dstDir = dst.Substring(0, lastIdx);
                FOS_System.String dstName = dst.Substring(lastIdx, dst.length - lastIdx);

                //console.WriteLine("dstDir: " + dstDir);
                //console.WriteLine("dstName: " + dstName);

                //New directory either creates the directory, or returns the existing directory
                Directory parentDir = NewDirectory(dstDir);
                //If the parent dir is null, the path must be invalid so we cannot create the
                //  dest file.
                if (parentDir != null)
                {
                    dstFile = mapping.TheFileSystem.NewFile(dstName, parentDir);
                }
                //If we still failed to create the file, then the path was totally invalid
                if (dstFile == null)
                {
                    console.WriteLine("Failed to create destination file!");
                    return;
                }

                console.WriteLine("Destination file created.");
            }
            else
            {
                console.WriteLine("Destination file already exists.");
            }

            //Get full path resolves the path of the file without using short-hands
            //  such as ./ and .. which can be used in the arguments to this method.
            //  So, GetFullPath allows us to do a consistent comparison of the paths.
            FOS_System.String srcFullPath = srcFile.GetFullPath();
            FOS_System.String dstFullPath = dstFile.GetFullPath();
            //If we are about to copy a file onto itself, well that wouldn't technically
            //  give us an issue given our copy implementation, but it is pretty pointless.
            //  Also, it would give a more sofisticated copy algorithm (e.g. block copying
            //  for large files) a big problem!
            if (srcFullPath == dstFullPath)
            {
                console.WriteLine("Atempted to copy a file to itself! (" + srcFullPath + ")");
                return;
            }
            else
            {
                console.WriteLine("Copying " + srcFullPath + " to " + dstFullPath);
            }

            //Get the streams to read from / write to
            FOS_System.IO.Streams.FileStream srcStr = srcFile.GetStream();
            FOS_System.IO.Streams.FileStream dstStr = dstFile.GetStream();

            //Temporary storage. Note: If the file is to big, this will just fail 
            //  as there won't be enough heap memory available
            byte[] data = new byte[(uint)srcFile.TheFileSystem.ThePartition.BlockSize];

            //Force stream positions
            srcStr.Position = 0;
            dstStr.Position = 0;

            console.Write("[");

            int percentile = (int)(uint)FOS_System.Math.Divide(srcFile.Size, 78u);
            int dist = 0;
            while ((ulong)srcStr.Position < srcFile.Size)
            {
//.........这里部分代码省略.........
开发者ID:rmhasan,项目名称:FlingOS,代码行数:101,代码来源:MainShell.cs

示例3: NewDirectory

        /// <summary>
        /// Creates a new directory (and parent directories). Used recursively.
        /// </summary>
        /// <param name="path">The full path of the directory (and parent directories) to create.</param>
        /// <returns>The new (or existing) directory.</returns>
        private Directory NewDirectory(FOS_System.String path)
        {
            //Output info to the user.
            console.WriteLine("Searching for directory: " + path);

            //Attempt to find the directory. If it already exists, we don't want to
            //  accidentally re-create it!
            Directory theDir = Directory.Find(path);
            //If the directory does not exist:
            if (theDir == null)
            {
                //Output info to the user.
                console.WriteLine("Creating directory...");

                //Attempt to get the file system mapping for the new directory
                FileSystemMapping mapping = FileSystemManager.GetMapping(path);
                //If the mapping was found:
                if(mapping != null)
                {
                    //Remove trailing "/" if there is one else the code below would end
                    //  up with a blank "new directory name"
                    if (path.EndsWith(FileSystemManager.PathDelimiter))
                    {
                        path = path.Substring(0, path.length - 1);
                    }

                    //  + 1 as we wish to include the path delimeter in parent dir name and
                    //      not in the new dir name.
                    //  Note: It is important to include the path delimeter at the end of the parent dir name
                    //        as the parent dir name may be a FS root which requires the trailing path delimeter.
                    int lastIdx = path.LastIndexOf(FileSystemManager.PathDelimiter) + 1;
                    FOS_System.String dirParentPath = path.Substring(0, lastIdx);
                    FOS_System.String newDirName = path.Substring(lastIdx, path.length - lastIdx);

                    console.WriteLine("Checking parent path: " + dirParentPath);
                    //This causes NewDirectory to become a recursive, self-calling
                    //  method which could potentially overflow. However, if has
                    //  the benefit that the entire new directory tree can be created
                    //  in one call, rather than having to create each directory and 
                    //  sub-directory one at a time.
                    Directory parentDir = NewDirectory(dirParentPath);
                    if (parentDir != null)
                    {
                        console.WriteLine("New dir name: " + newDirName);
                        //Create the directory
                        theDir = mapping.TheFileSystem.NewDirectory(newDirName, parentDir);
                        console.WriteLine("Directory created.");
                    }
                    else
                    {
                        console.WriteLine("Failed to find or create parent directory.");
                    }
                }
                else
                {
                    console.WriteLine("File system mapping not found.");
                }
            }
            else
            {
                console.WriteLine("Directory already exists.");
            }

            return theDir;
        }
开发者ID:rmhasan,项目名称:FlingOS,代码行数:70,代码来源:MainShell.cs

示例4: GetShortName

 /// <summary>
 /// Gets the short name for the specified long name.
 /// </summary>
 /// <param name="longName">The long name to shorten.</param>
 /// <param name="isDirectory">Whether the long name is for a directory or not.</param>
 /// <returns>The short name parts. Directory=1 part, file=2 parts (name + extension).</returns>
 private static List GetShortName(FOS_System.String longName, bool isDirectory)
 {
     if (isDirectory)
     {
         List result = new List(1);
         result.Add(longName.Substring(0, 8).PadRight(11, ' '));
         return result;
     }
     else
     {
         List result = new List(2);
         List nameParts = longName.Split('.');
         if (nameParts.Count > 1)
         {
             result.Add(((FOS_System.String)nameParts[0]).Substring(0, 8).PadRight(8, ' '));
             result.Add(((FOS_System.String)nameParts[1]).Substring(0, 3).PadRight(3, ' '));
         }
         else
         {
             result.Add(longName.Substring(0, 8).PadRight(8, ' '));
             result.Add(((FOS_System.String)"").PadRight(3, ' '));
         }
         return result;
     }
 }
开发者ID:rmhasan,项目名称:FlingOS,代码行数:31,代码来源:FATFileSystem.cs


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