예제 #1
0
        public static string ReadTextFile(string path)
        {
            try
            {
                FS.Listing.DirectoryEntry file = device.GetFile(path);
                Stream stream = file.GetFileStream();

                if (stream.CanRead)
                {
                    byte[] txt = new byte[stream.Length];
                    stream.Read(txt, 0, (int)stream.Length);
                    return(Encoding.Default.GetString(txt));
                }
                else
                {
                    return("File not reading for reading!");
                }
            }
            catch (Exception ex) { return(ex.Message); }
        }
예제 #2
0
 // get file info
 public static Cosmos.System.FileSystem.Listing.DirectoryEntry GetFileInfo(string file)
 {
     if (FileExists(file))
     {
         try
         {
             Cosmos.System.FileSystem.Listing.DirectoryEntry attr = Driver.GetFile(file);
             return(attr);
         }
         catch (Exception ex)
         {
             CLI.WriteLine("Error occured when trying to retrieve file info", Graphics.Color.Red);
             CLI.Write("[INTERNAL] ", Graphics.Color.Red); CLI.WriteLine(ex.Message, Graphics.Color.White);
             return(null);
         }
     }
     else
     {
         CLI.WriteLine("Could not locate file \"" + file + "\"", Graphics.Color.Red);
         return(null);
     }
 }
예제 #3
0
        private void ListContents(string path)
        {
            try
            {
                string[] folders = PMFAT.GetFolders(path);
                string[] files   = PMFAT.GetFiles(path);

                CLI.WriteLine("Showing contents of directory \"" + path + "\"");

                // draw folders
                for (int i = 0; i < folders.Length; i++)
                {
                    CLI.WriteLine(folders[i], Color.Yellow);
                }

                // draw files
                for (int i = 0; i < files.Length; i++)
                {
                    Cosmos.System.FileSystem.Listing.DirectoryEntry attr = PMFAT.GetFileInfo(path + files[i]);
                    if (attr != null)
                    {
                        CLI.Write(files[i], Color.White);
                        CLI.SetCursorPos(30, CLI.CursorY);
                        CLI.WriteLine(attr.mSize.ToString() + " BYTES", Color.Gray);
                    }
                    else
                    {
                        CLI.WriteLine("Error retrieiving file info", Color.Red);
                    }
                }

                CLI.WriteLine("");
                CLI.Write("Total folders: " + folders.Length.ToString());
                CLI.WriteLine("        Total files: " + files.Length.ToString());
            }
            catch (Exception ex) { }
        }