Performance of File.delete under Linux operating system

Source: Internet
Author: User

in my previous essay, "a point of view on the File.delete method, the File.delete method is tested on the Windows operating system. This time, use on Linux osMonoof theLatest Version 1.2.5 Editiontest the File.delete method.
here is the basic information for my computer running the Linux operating system:

[Email protected]:~/work$ cat/etc/issue.net
Ubuntu 6.10
[Email protected]:~/work$ Uname-rm
2.6.17-12-server i686
[Email protected]:~/work$ Mono--version
Mono JIT Compiler version 1.2.5 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. Www.mono-project.com
TLS: __thread
Gc:included Boehm (with typed GC)
Sigsegv:normal
Architecture:x86
Disabled:none
[Email protected]:~/work$ GMCs--version
Mono C # compiler version 1.2.5.0
[Email protected]:~/work$ Mono Clrver.exe
Operating system version: Unix 2.6.17.12
Common Language runtime version: 2.0.50727.42
[Email protected]:~/work$
we use the following procedure to test the performance of File.delete under the Linux operating system:

usingSystem;
usingSystem.IO;

Sealed classTest
{
Static voidMain ()
{
Try
{
Console.Write ("Please enter the file name to delete:");
stringFileName=Console.ReadLine ();
if(FileName== "NULL") FileName= NULL;
if(FileName== "Zero") FileName= " /";
File.delete (FileName);
Console.WriteLine ("File.delete Success");
}
Catch(Exception ex)
{
Console.WriteLine ("Error:" +Ex. ToString ());
}
}
}

The results of the operation are as follows:

file name call File.delete method directly
[email  protected]:~/work$  Mono test.exe
0 length string Please enter the file name to delete:
Error: System.:   path
  at System.IO.File.Delete (System.String path) [0x00000]
  at test.main (system.string[] args) [0x00000]
illegal character Please enter the file name to delete: zero
Error: System.:   path
  at System.IO.File.Delete (System.String path) [0x00000]
  at test.main (system.string[] args) [0x00000]
null reference Please enter the file name to be deleted: null
Error: System.:   Argument cannot be null.
Parameter name:path

  at System.IO.File.Delete (System.String path) [0x00000]
   At Test.main (system.string[] args) [0x00000]
invalid path Please enter the file name to delete: None/a.txt
Error: System.io.:   Destination directory not found:none
  at System.IO.File.Delete (System.String path) [0x00000]
  at test.main (system.string[] args) [0x00000]
filename too long Please enter the file name to be deleted:-this-string ' s-length-is-256-
Error: System.io.:   Path is too long. Path:-this-string ' s-length-is-256-
  at System.IO.Directory.Exists (System.String path) [ 0X00000]
  at System.IO.File.Delete (System.String path) [0x00000]
  at test.main ( system.string[] args) [0x00000]
a directory Please enter the file name to delete:/
Error: System. UnauthorizedAccessException :   /is a directory
  at System.IO.File.Delete (System.String Path) [0x00000]
  at test.main (system.string[] args) [0x00000]
file with no permissions Please enter the file name to delete:/etc/passwd
Error: System.:   Access to the path '/etc/passwd ' is denied.
  at System.IO.File.Delete (System.String path) [0x00000]
  at test.main (system.string[] args) [0x00000]
Files that are in use Please enter the file name to delete: Test.exe
File.delete success
Read-only files Please enter the file name to delete: Readonly.file
File.delete success
Files that do not exist Please enter the file name to delete: None.file
File.delete success
The normal file Please enter the file name to delete: Readwrite1.file
File.delete success

A few notes:
1. In the table above, the bold black text is the "ex" in the program. ToString () "replaced by" ex. Message ", which is exactly how we normally display the error message. However, in the case of "0 length strings" and "illegal characters" in the table, the error message is only "path", which is very unfriendly to the user. In the Windows operating system, the corresponding error messages are: "The form of the path is not legal" and "the path has illegal characters."
2. The maximum allowable length for filenames in the Linux operating system I am using is 255 characters, while in Windows XP Professional SP2 and Windows Server 2003 SP2 are 251 and 248 characters respectively 。
3. In the Linux operating system, the characters that cannot be used as directory names are only (' s '). Characters that cannot be used as filenames are only (' + ') and ('/') two. On Windows-based desktop platforms, invalid path characters may include ascii/unicode characters from 1 to 31, as well as quotation marks ("), less than (<), greater than sign (>), pipe symbol (|), backspace (\b), empty (), and tab (\ t) 。
4. From the table above you can see that "files in use" and "read-only Files" can also be successfully deleted by the File.delete method.
below are the conditions for using the "RM" command of the Linux operating system:

[Email protected]:~/work$ ls-l Readwrite1.file
- rw-r--r--1 Ben Ben 2007-09-02 13:56 Readwrite1.file
[Email protected]:~/work$ RM readwrite1.file
[Email protected]:~/work$ ls-l Readwrite1.file
Ls:readwrite1.file:No such file or directory
[Email protected]:~/work$
[Email protected]:~/work$ ls-l Readonly.file
- r--r--r--1 Ben Ben 1624 2007-09-02 13:57 Readonly.file
[Email protected]:~/work$ RM readonly.file
Rm:remove write-protectedRegular file ' Readonly.file '? y
[Email protected]:~/work$ ls-l Readonly.file
Ls:readonly.file:No such file or directory
[Email protected]:~/work$
[Email protected]:~/work$ ls-l/etc/passwd
-rw-r--r--1 RootRoot 1168 2007-08-09 14:33/etc/passwd
[Email protected]:~/work$ rm/etc/passwd
Rm:remove write-protectedRegular file '/etc/passwd '? y
Rm:cannot remove '/etc/passwd ': Permission denied
[Email protected]:~/work$ ls-l/etc/passwd
-rw-r--r--1 root root 1168 2007-08-09 14:33/etc/passwd
[Email protected]:~/work$
as you can see, deleting a read-only file using the RM command asks the user if they really need to delete the file. Although the File.delete method cannot ask whether the user really needs to delete the read-only file, it cannot silently delete the read-only file, but should throw an exception.

In general , Mono is still very successful, and many. NET programs of the Windows operating system are copied directly to Linux with mono and can be run without recompiling. Although she still has such a small problem, but his flaws, and she is still improving.

Copyright NOTICE: This article for Bo Master http://www.zuiniusn.com original article, without Bo Master permission not reproduced.

Performance of File.delete under Linux operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.