rmdir.java
来自「JAVA 数学程序库 提供常规的数值计算程序包」· Java 代码 · 共 62 行
JAVA
62 行
package jmathlib.toolbox.io;
import jmathlib.core.tokens.*;
import jmathlib.core.functions.ExternalFunction;
import java.io.*;
/**An external function for changing to another directory */
public class rmdir extends ExternalFunction
{
public OperandToken evaluate(Token[] operands)
{
if (getNArgIn(operands) != 1)
throwMathLibException("rmdir: number of arguments != 1");
if (!(operands[0] instanceof CharToken))
throwMathLibException("rmdir: argument must be a string");
String name = ((CharToken)operands[0]).toString();
File file = null;
try
{
file = new File(getWorkingDirectory(),name);
}
catch (Exception e)
{
throwMathLibException("rmdir: IO exception");
}
// check if file is really a directory and not a file
if (!file.isDirectory())
throwMathLibException("rmdir: is not a directory");
// delete directroy
if (!file.delete())
throwMathLibException("rmdir: did not work");
return null;
} // end eval
}
/*
@GROUP
IO
@SYNTAX
rmdir(directory)
@DOC
Deletes a given directory.
@EXAMPLES
<programlisting>
rmdir("bar");
</programlisting>
@NOTES
Directory must be empty in order to be removed.
@SEE
cd, createnewfile, dir, exist, mkdir, delete, isfile, isdirectory, ishidden, lastmodified
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?