Asp.net| Program There are a number of ways to manage files or directories using the ASP.net program, such as Directory.createdirectory,directoryinfo.create to create a directory, but today we introduce another alternative way to create a directory, which is to use the cmd command To manage.
People who have used DOS commands know that DOS commands can do a lot of things, such as Dir can enumerate files and subdirectories in a directory. This time, we use the ASP.net program to invoke CMD's command to manage the file.
Here's how to call Cmd.exe:
public bool cmd (string argm)
{
Start creating files
Process P = new process ();
p.StartInfo.FileName = "cmd.exe";
P.startinfo.useshellexecute = false;
P.startinfo.redirectstandardinput = true;
P.startinfo.redirectstandardoutput = true;
P.startinfo.redirectstandarderror = true;
P.startinfo.createnowindow = true;
Try
{
P.start ();
P.standardinput.writeline (ARGM);
P.standardinput.writeline ("Exit");
P.standardoutput.readtoend ();
P.close ();
return true;
}
Catch
{
return false;
}
}
Where ARGM is to represent the execution of the cmd command, such as I want to create a folder, using the following methods:
BOOL created = cmd (@ "MD e:\abc\mydir");
The commands for file management using CMD are as follows: Creating a folder MD
Delete Folder Rd
Delete File Del
Rename folder move
Renaming files Rename
Replication Folder xcopy
Copy file copy
Move a file or folder